View unanswered posts | View active topics It is currently Mon Aug 31, 2015 4:49 am






Reply to topic  [ 26 posts ]  Go to page Previous  1, 2
Robocup Junior 2010 
Author Message
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3585
Location: Rotterdam, The Netherlands
Post Re: Robocup Junior 2010
No, there is no difference. They are both ground.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Jan 18, 2011 3:44 pm
Profile WWW
Rookie

Joined: Wed Mar 23, 2011 3:10 pm
Posts: 1
Post Re: Robocup Junior 2010
Hello!

I've got a TPA81 heat sensor, and I've wired it to my NXT as described by Xander in the earlier comments of this thread. The problem now is using the sensory data in a useful way. I have virtually no understanding of how to deal with the data that are passed from the thermal array sensor to the NXT. That is to say, my ROBOTC experience, while pretty extensive, is limited to native and third party sensor that have drivers to deal with all of these raw data.

In my first (and admittedly ignorant) pass at this, I tried a very basic call to the sensor, printing the result to the screen:

nxtDisplayCenteredBigTextLine(6, "%d", SensorValue[S1]);

Not surprisingly this didn't do much. Given my vague understanding, the NXT has to ask the slave (in this case the heat sensor) to pass some information back to the brick. Any suggestions for how to get up to speed with this? Thanks in advance for your help!


-Brook


Fri Mar 25, 2011 5:13 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3585
Location: Rotterdam, The Netherlands
Post Re: Robocup Junior 2010
Hi Brook,

I am not sure if I will have time to do this today, but I'd be happy to see if I can come up with some code in the next few days. Send me a PM tomorrow to remind me!

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sat Mar 26, 2011 2:30 am
Profile WWW
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3585
Location: Rotterdam, The Netherlands
Post Re: Robocup Junior 2010
Here's a driver and a test program. I don't know for sure if it'll work since I don't have one of these.

pixeldata is an array with the following layout:
Image

Let me know how it goes.

- Xander


Attachments:
TPA81-driver.h [1.89 KiB]
Downloaded 506 times
TPA81-test1.c [1.51 KiB]
Downloaded 518 times

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]
Thu Mar 31, 2011 1:32 am
Profile WWW
Expert
User avatar

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 148
Location: New Jersey
Post Re: Robocup Junior 2010
I got two of these thermal sensors.

I found an interesting problem with one of them. Symptom:
- executing a test with heat sensor#2, data looks good
- terminating the program. Rerun. Data looks invalid.
- restart the controller, rerun the test. Data looks good again.

We went thru this sequence a few times with #1 and #2 indpendently, switching wires, etc. Same symptom happens with one of the wires. I'll have to wait until next week to play with the problematic wire. For the time being, I wonder if anyone may have an advice on this one!?

So, looks like something needs to be reset!?

_________________
==Elizabeth Mabrey


Sat Apr 09, 2011 7:16 am
Profile WWW
Rookie

Joined: Tue Mar 24, 2015 1:44 pm
Posts: 3
Post Re: Robocup Junior 2010
Hello!
I currently try to connect and program the TPA81 with the EV3! I adapted the TPA81 NXT-program from Xander, but it didn't work. So I tried to measure the data with my oscilloscope.
But EV3 seems not to produce any I2C data! Even if I use the EV3 I2C Test Utility, it seems as if there is no signal sent from the EV3. Is there something that prevents the EV3 from sending I2C data, if there is nothing connected?
Please help me! I need a solution! Ohterwise my pupils are not able to continue with their work!


Tue Mar 24, 2015 1:57 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3585
Location: Rotterdam, The Netherlands
Post Re: Robocup Junior 2010
Yeah, the EV3 does auto-id'ing of the connection type. So if you hook up your scope to the connectors without a sensor present, it simply won't work.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Apr 01, 2015 2:50 am
Profile WWW
Rookie

Joined: Tue Mar 24, 2015 1:44 pm
Posts: 3
Post Re: Robocup Junior 2010
Hello Xander! Thank you for your response!
What I tried until now is:
Connect the NXT ultrasonic sensor with the EV3 and watch the I2C protocol with my oscilloscope. This works! And: I could see some communication with the sensor without my program started. Is this Auto-IDing?
Next step:
Connect the NXTMMX of mindsensors with the EV3 and watch the I2C protocol with my oscilloscope. I again saw the Auto-IDing? When I started my program I could see the command with increasing address on my oscillocope, but the sensor did not answer. Even not at address 6, which should be the correct I2C address of the NXTMMX. But this could be a defect NXTMMX.
Third step:
I connected the TPA81 with pullup-Rs of 100k. But in this case there is nothing that was sent from the EV3. Is the reason for this, that the auto-IDing doesn't work for my TPA81? How can I solve this problem?

Please could help me again. If I don't find a solution for this until friday, 10.4.2015, I have to cancel my team from Robocup.
I used the following program for my tests:

Code:
#pragma config(Sensor, S2,     ,               sensorEV3_GenericI2C)
#pragma config(Sensor, S3,     ,               sensorEV3_GenericI2C)
#pragma config(Sensor, S4,     ,               sensorEV3_GenericI2C)
#pragma config(MotorPidSetting,  motorA,  255, 255, 65535, 255, 255,   65535, 65535, 65535)
#pragma config(MotorPidSetting,  motorB,  255, 255, 65535, 255, 255,   65535, 65535, 65535)
#pragma config(MotorPidSetting,  motorC,  255, 255, 65535, 255, 255,   65535, 65535, 65535)
#pragma config(MotorPidSetting,  motorD,  255, 255, 65535, 255, 255,   65535, 65535, 65535)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

//////////////////////////////////////////////////////////////////////////////////////////
//
//                           I2C Coding Source Code Examples
//                           ===============================
//
// Contains code snippets for working with the Legacy NXT I2C sensors on a EV3 brick.
//
////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////
//
//                waitForI2CReply(TSensors nPortIndex, const int nReplyLength)
//
// Function will delay waiting for last I2C transaction to finish.
//
//////////////////////////////////////////////////////////////////////////////////////////

bool waitForI2CReply(tSensors nPortIndex)
{
   while (nI2CStatus[nPortIndex] == i2cStatusPending)
      wait1Msec(1);

   //if (nI2CBytesReady[nPortIndex] != nReplyLength)
   //   return false;

   return true;
}


//
// Alternate version showing more complicated error checking
//

bool checkErrorStatus(tSensors nPortIndex, const int nReplyLength)
{
   while (nI2CStatus[nPortIndex] == i2cStatusPending)
      wait1Msec(1); // Waiting for I2C transaction to complete

   //
   // Handle all possible return status. You may want to customize the
   // code for your particular situation.
   //
   switch (nI2CStatus[nPortIndex])
   {
   case i2cStatusNoError:
      return true;

   case i2cStatusPending:
      // Shouldn't reach here because of preceding 'while' clause
      return false;

   case i2cStatusBadConfig:
      // Sensor is not configured for I2C messaging.
      return false;

   case i2cStatusFailed:
      // re-initialize sensor. An I2C messaging error occurred.
      return false;

   default:
      // "Illegal" value
      return false;
   }
}


//////////////////////////////////////////////////////////////////////////////////////////
//
//                           Read from an I2C Device
//
// Sends a message to I2C sensor to read data from the device. You'll have to poll the
// status of the I2C communications channel to tell when the 'read' is complete.
//
//////////////////////////////////////////////////////////////////////////////////////////

bool sendSensorRead(tSensors nPortIndex, const ubyte &nSendMsg, const int nReplyLength)
{
   TI2CStatus nStatus;

   if (nI2CStatus[nPortIndex] == i2cStatusPending)
      return false;   // Can't send message to a busy device

   nStatus = sendI2CMsg(nPortIndex, &nSendMsg, nReplyLength);
   return (nStatus == i2cStatusNoError);
}

//////////////////////////////////////////////////////////////////////////////////////////
//
//                        readI2CReply(TSensors nPortIndex)
//
// Collects the reply bytes from an I2C message.
//
//////////////////////////////////////////////////////////////////////////////////////////

bool readSensorReply(tSensors nPortIndex, ubyte *pReplyMsg, const int nReplyLength)
{
   TI2CStatus nStatus;

   if (!waitForI2CReply(nPortIndex))
   {
     memset(pReplyMsg, 0, nReplyLength);
     return false;
   }

   nStatus = readI2CReply(nPortIndex, pReplyMsg, nReplyLength);
   return (nStatus == i2cStatusNoError);
}


////////////////////////////////////////////////////////////////////////////////////////////
//
//          Sample Task to Continuously read the sensor characteristics
//
////////////////////////////////////////////////////////////////////////////////////////////

int nMsgCountGood = 0;
int nMsgCountTimeout = 0;

task main()
{
   short nAddress;
   int   nLastGoodAddress    = -1;
   bool  bGoodAddress[256];
   int i;

   const tSensors sensorPort = S3;
   const int kI2CAddress    = 0xD0;    // You may want to make this a function parameter
   const int kRegisterIndex = 0x00;    // You may want to make this a function parameter

   static ubyte nReadDeviceID[] =
   {
      2,                   // This is length field for transmitted message.
      kI2CAddress,         // The I2C address of the device. Almost all devices use value '0x02'
      kRegisterIndex,      // The internal register index within the sensor to start writing at.
   };

   const int kReplyLength = 8;         // You might want to make this a function parameter.
   static ubyte nReplyBytes[kReplyLength];

  clearDebugStream();
   for (nAddress = 0; nAddress <= 255; ++nAddress)
      bGoodAddress[nAddress] = false;

   for (nAddress = 0; nAddress < 256; nAddress += 2)
   {
    clearTimer(T1);
    nReadDeviceID[1]=nAddress;
    sendSensorRead(sensorPort, nReadDeviceID[0], kReplyLength);
    while (true)
    {
      
       if ((nI2CStatus[sensorPort] == i2cStatusPending) || (nI2CStatus[sensorPort] == i2cStatusStartTransfer))
       {
          if (time1[timer1] > 48)
          {
             ++nMsgCountTimeout;
             break;
          }
       }
       else if (nI2CStatus[sensorPort] == i2cStatusNoError)
       {
          readSensorReply(sensorPort, &nReplyBytes[0], kReplyLength);
            bGoodAddress[nAddress] = true;
            displayCenteredBigTextLine(0, "Address: %d", nAddress);
            for(i=0; i<4; i++)
               displayCenteredBigTextLine(3*i+3, "Byte %d: %d", i, nReplyBytes[i]);
           while(!getButtonPress(7))
           {
           }
           while(getButtonPress(7))
           {
           }

          break;
       }
       else
       {
           ++nMsgCountTimeout;
          break;
       }
    }
      displayCenteredBigTextLine(0, "Address: %d", nAddress);
      displayCenteredBigTextLine(3, "Status: %d", nI2CStatus[sensorPort]);
     while(!getButtonPress(7))
     {
     }
     while(getButtonPress(7))
     {
     }
   
  }

  displayCenteredBigTextLine(0, "Ende!");

  writeDebugStreamLine("Total: %d", nMsgCountGood + nMsgCountTimeout);
  writeDebugStreamLine("Good: %d", nMsgCountGood);
  writeDebugStreamLine("Tout: %d", nMsgCountTimeout);
  while(!getButtonPress(7))
  {
  }
}


Sat Apr 04, 2015 4:46 am
Profile
Rookie

Joined: Tue Mar 24, 2015 1:44 pm
Posts: 3
Post Re: Robocup Junior 2010
I found a solution for the Auto-ID by myself.
If you want your device to be detected as I2C device, you have to connect Pin2 of the EV3 connector with Ground. Pin 5 and 6 have to be connected with +5V which is fulfilled because of the Pullup-Rs. Additionally I didn't connect Pin1 to anything (also not to Ground).
The EV3 sends the correct signal right now, but the TPA81 isn't able to detect it.
I think that the reason for that is the bad quality of the SDA signal.
I added a photo of my osciiloscope screen, which shows the SDA signal. Bit 8, 7 and 6 are set which corresponds to I2C address 0xD0. But the acknowledge bit (9th bit) doesn't seem to work correct (should be zero!).
Attachment:
SDA signal TPA81.jpg
SDA signal TPA81.jpg [ 404.37 KiB | Viewed 1881 times ]


Sat Apr 04, 2015 10:15 am
Profile
Rookie

Joined: Tue Apr 07, 2015 10:36 pm
Posts: 1
Post Re: Robocup Junior 2010
Peter, I've been having a similar issue. I've banged together some code that is working for me, maybe it will work for you.

First, the driver, which provides three functions:
1) read_tpa81_pixels which returns a pointer to an array of 8 integers, corresponding to the 8 temperatures in deg. C.
2) read_tpa81_max_pixel which returns the warmest of the 8 pixels as an integer.
3) read_tpa81_ambient which returns the ambient temperature inside the sensor as an integer.

Code:
/* Driver for TPA81 Thermopile

TPA_81_driver.h provides an API for the TPA 81 thermopile array for sensing
infrared light in the 2-22 micrometer wavelength (radiant heat).

This code was written using RobotC version 4.30 for NXT for Windows 7 on Mac Parallels.
I have not tested it on any other system.

License: You may use this code as you wish, but you should give credit where credit is due.

This code uses a lot of information gleaned from reading code by Xander Soldaat
(mightor_at_gmail.com), including, but not limited to, his TPA81-driver.h version 0.5, released
08 March 2009.

\author Marcus Jaiclin (jaiclinm_at_mercersburg.edu)
\date 2015 04 07
\version 0.1
*/

int * read_tpa81_pixels(tSensors port_link)
{
   ubyte * request_ptr;
   ubyte request[3];
   request_ptr = &request;
   memset (request_ptr, 0, 3);
   request[0] = 2;
   request[1] = 0xD0;
   request[2] = 1;
   sendI2CMsg(port_link, request_ptr, 10);
//   writeDebugStreamLine("Sensor data bytes ready: %d", nI2CBytesReady[port_link]);
//   writeDebugStreamLine("Status: %d", nI2CStatus[port_link]);
// status results: 32 = STAT_COMM_PENDING, 0 = NO_ERR, -32 = ERR_CHAN_NOT_READY
//     -35 = STAT_COMM_BUS_ERR
   while (nI2CStatus[port_link] == STAT_COMM_PENDING)
   {
      sleep(2);
   }
//   writeDebugStreamLine("Status: %d", nI2CStatus[port_link]);
   if (nI2CStatus[S1] == NO_ERR)
   {
      ubyte * reply_ptr;
      ubyte replymsg[10];
      reply_ptr = &replymsg;
      memset (reply_ptr, 0, 10);
      readI2CReply(port_link, reply_ptr, 10);
      int pixel_array[8];
      for (int i=1; i<=8; i++)
      {
         pixel_array[i-1] = replymsg[i];
      }
      int * pixel_array_ptr;
      pixel_array_ptr = &pixel_array;
//      for (int i=0; i<8; i++)
//      {
//         writeDebugStream("%d ", pixel_array_ptr[i]);
//      }
//      writeDebugStreamLine("");
      return pixel_array_ptr;
   } else {
      return NULL;
   }
}

int read_tpa81_max_pixel (tSensors port_link)
{
   ubyte * request_ptr;
   ubyte request[3];
   request_ptr = &request;
   memset (request_ptr, 0, 3);
   request[0] = 2;
   request[1] = 0xD0;
   request[2] = 1;
   sendI2CMsg(port_link, request_ptr, 10);
//   writeDebugStreamLine("Sensor data bytes ready: %d", nI2CBytesReady[port_link]);
//   writeDebugStreamLine("Status: %d", nI2CStatus[port_link]);
// status results: 32 = STAT_COMM_PENDING, 0 = NO_ERR, -32 = ERR_CHAN_NOT_READY
//     -35 = STAT_COMM_BUS_ERR
   while (nI2CStatus[port_link] == STAT_COMM_PENDING)
   {
      sleep(2);
   }
//   writeDebugStreamLine("Status: %d", nI2CStatus[port_link]);
   unsigned int max_heat = 0;
   if (nI2CStatus[S1] == NO_ERR)
   {
      ubyte * reply_ptr;
      ubyte replymsg[10];
      reply_ptr = &replymsg;
      memset (reply_ptr, 0, 10);
      readI2CReply(port_link, reply_ptr, 10);
      for (int i=1; i<=8; i++)
      {
         if (replymsg[i] > max_heat)
         {
            max_heat = replymsg[i];
         }
      }
   }
   return max_heat;
}

int read_tpa81_ambient (tSensors port_link)
{
   ubyte * request_ptr;
   ubyte request[3];
   request_ptr = &request;
   memset (request_ptr, 0, 3);
   request[0] = 2;
   request[1] = 0xD0;
   request[2] = 1;
   sendI2CMsg(port_link, request_ptr, 10);
//   writeDebugStreamLine("Sensor data bytes ready: %d", nI2CBytesReady[port_link]);
//   writeDebugStreamLine("Status: %d", nI2CStatus[port_link]);
// status results: 32 = STAT_COMM_PENDING, 0 = NO_ERR, -32 = ERR_CHAN_NOT_READY
//     -35 = STAT_COMM_BUS_ERR
   while (nI2CStatus[port_link] == STAT_COMM_PENDING)
   {
      sleep(2);
   }
//   writeDebugStreamLine("Status: %d", nI2CStatus[port_link]);
   unsigned int ambient_heat = 0;
   if (nI2CStatus[S1] == NO_ERR)
   {
      ubyte * reply_ptr;
      ubyte replymsg[10];
      reply_ptr = &replymsg;
      memset (reply_ptr, 0, 10);
      readI2CReply(port_link, reply_ptr, 10);
      ambient_heat = replymsg[0];
   }
   return ambient_heat;
}


Then, my test code:

Code:
#pragma config(Sensor, S1,     tpa81,          sensorI2CCustom)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "TPA_81_driver.h"

task main()
{
   clearDebugStream();
   int * pixel_ptr;
   pixel_ptr = read_tpa81_pixels(tpa81);
   if (pixel_ptr != NULL)
   {
      for (int i=0; i<=7; i++)
      {
         writeDebugStream("%d ", pixel_ptr[i]);
      }
      writeDebugStreamLine("");
   }
   else
   {
      writeDebugStreamLine("I2C Bus Error.");
   }
   int hot_pixel = read_tpa81_max_pixel(tpa81);
   writeDebugStreamLine("%d", hot_pixel);
   int ambient = read_tpa81_ambient(tpa81);
   writeDebugStreamLine("%d", ambient);
}



I hope this helps,
Dr. J


Tue Apr 07, 2015 10:45 pm
Profile
Rookie

Joined: Sat Jun 13, 2015 11:10 am
Posts: 2
Post Re: Robocup Junior 2010
Thank you both...
thanks for information

Yes, I am particularly interested to know this device works to detect the heat specification from Rescue B...

[url]Imagehttp://imgupp.com/1433173618.html[/url]


Sat Jun 13, 2015 11:27 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 26 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.