Temperature sensor

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: roger, 99jonathan, imaqine

Temperature sensor

Postby kspacja » Thu Nov 10, 2011 3:26 pm

I have a problem with temperature sensor. I read this sensor by bluetooth, but I have always this same result of measure, although I warm up sensor. I use RAW-date mode. The sensor works good - I used view mode on nxt bricks and there is good and changing results of measures. Application, what I write, I implement in Java on PC. For example touch sensor works well via bluebooth - my app receive results that are changing depending on touching sensor.

I ask for advise: Maybe there is some issue with this sensor or I have to do something special.
kspacja
New User
 
Posts: 6
Joined: Thu Nov 10, 2011 3:01 pm

Re: Temperature sensor

Postby skoehler » Thu Nov 10, 2011 3:48 pm

Which sensor do you use exactly? Which class do you use to access it on PC-side?
Are the reading OK, if you upload a java program which uses the sensor to the NXT?
skoehler
leJOS Team Member
 
Posts: 1114
Joined: Thu Oct 30, 2008 4:54 pm

Re: Temperature sensor

Postby kspacja » Thu Nov 10, 2011 3:54 pm

It's 9749 NXT Temperature Sensor. I use only java. I don't use leJOS. I just read stream of dates that are sent via Bluetooth from NXT Bricks.
kspacja
New User
 
Posts: 6
Joined: Thu Nov 10, 2011 3:01 pm

Re: Temperature sensor

Postby skoehler » Thu Nov 10, 2011 4:03 pm

kspacja wrote:I use only java. I don't use leJOS. I just read stream of dates that are sent via Bluetooth from NXT Bricks.

So the NXT brick is running the Lego firmware and not the leJOS firmware? This constellation might be pretty badly tested.
skoehler
leJOS Team Member
 
Posts: 1114
Joined: Thu Oct 30, 2008 4:54 pm

Re: Temperature sensor

Postby skoehler » Thu Nov 10, 2011 4:04 pm

kspacja wrote:It's 9749 NXT Temperature Sensor.


I know somebody who owns this sensor. I can ask him to test this.
skoehler
leJOS Team Member
 
Posts: 1114
Joined: Thu Oct 30, 2008 4:54 pm

Re: Temperature sensor

Postby skoehler » Thu Nov 10, 2011 9:15 pm

kspacja wrote:I don't use leJOS. I just read stream of dates that are sent via Bluetooth from NXT Bricks.


Can you provide the PC-side program for reading the values?
Can you provide the NXT-side program that sends the values?
skoehler
leJOS Team Member
 
Posts: 1114
Joined: Thu Oct 30, 2008 4:54 pm

Re: Temperature sensor

Postby kspacja » Fri Nov 11, 2011 3:32 pm

There is no program on brick.

In PC-side I have the following in dates in bytes in hexdecimal:
Byte 0: 2
Byte 1: 7
Byte 2: 0
Byte 3: 0
Byte 4: 1
Byte 5: 0
Byte 6: 2
Byte 7: 0
Byte 8: FE
Byte 9: 3
Byte 10: 0
Byte 11: 0
Byte 12: 0
Byte 13: 0
Byte 14: 0
Byte 15: 0

http://cache.lego.com/upload/contentTem ... A8B567.zip - this is a link to documentation of bluetooth command.
kspacja
New User
 
Posts: 6
Joined: Thu Nov 10, 2011 3:01 pm

Re: Temperature sensor

Postby skoehler » Fri Nov 11, 2011 3:37 pm

Please post the PC-side java-code to reproduce the problem.
skoehler
leJOS Team Member
 
Posts: 1114
Joined: Thu Oct 30, 2008 4:54 pm

Re: Temperature sensor

Postby kspacja » Wed Nov 16, 2011 11:35 am

But I'm sure that PC-side is good, because it works well with other sensors. On PC first I send setinputmode bytes (0x00, 0x05, 0x00, 0x02, 0x00) and next I send getinputvalues (0x00, 0x07, 0x00) byte. And I have response that I gave in previous post.

I think there is a special way communication with this temperature sensor - something like with ultrasonic sensor.
kspacja
New User
 
Posts: 6
Joined: Thu Nov 10, 2011 3:01 pm

Re: Temperature sensor

Postby skoehler » Wed Nov 16, 2011 1:23 pm

There are two reasons why I ask for the PC-side code:
  • it saves time for me, and it makes it easier for me to reproduce exactly what you're seeing
  • it avoids any misunderstandings and uncovers errors in areas of your program that you might not have throught about yet

And to be honest, I'm not really sure what you're trying to tell me in your last post.
skoehler
leJOS Team Member
 
Posts: 1114
Joined: Thu Oct 30, 2008 4:54 pm

Re: Temperature sensor

Postby kspacja » Wed Nov 16, 2011 3:01 pm

Look to the appendix (link, which I gave). There is explanation, what is "setinputmode" and "getinputvalues". My code brings nothing. In code there's only connecting with bluetooth device (NXT Bricks, without problem), next - send few bytes, which set "input mode" (0x00, 0x05, 0x00, 0x02 - sensor type, 0x00 - sensor mode), next send command "get input values" (it's still in bytes) - 0x00, 0x07, 0x00.

Code: Select all
Connection conn = new Connection("btspp://0016530BD2F6:1;authenticate=false;encrypt=false;master=false", 100);

System.out.println("Receive bytes...");
      
      
conn.send(new byte[] {0x00, 0x05, 0x00, 0x02, 0x0b});
Thread.sleep(2000);
      
      
while(true){
         
   conn.send(new byte[] {0x00, 0x07, 0x00});   
   Thread.sleep(100);
   System.out.println(conn.print(conn.receive()));         
         
}


Connection class

Code: Select all
public class Connection {

   private String serviceURL;
   

   private LinkedList<byte[]> received;
   private LinkedList<byte[]> toSend;
   
   Timer timer;

   InputStream is;
   OutputStream os;
   
   public int drukuj(byte[] buffer) {
      
      byte a = 0, b = 0, a2 = 0, b2 = 0;
      
      if (buffer!=null) {
         for (int i=0;i<buffer.length;i++){
              System.out.println("Byte " + i + ": " + (Integer.toHexString(byteToInt(buffer[i]))+" ").toUpperCase() );
         
            if (i == 8) b2 = buffer[i];
            else if (i == 9) a2 = buffer[i];
            
            if (i == 10) b = buffer[i];
            else if (i == 11) a = buffer[i];
         }
         
         int angle = (a << 8) + b;
         int angle2 = (a2 << 8) + b2;
         
         //System.out.println("ANGLE 1: " + (angle - 204));
         
         //int res = (int)(((double)(angle - 206)) / 3);
         
         //if (res < 0) res = (int)(res * 2);
         
         int res = angle2
         
         return res;
      }
      return 0;
          
      
   }

   
   // konstruktor(adres uslugi, interval)
   public Polaczenie(String url, int interval) {
      doWyslania = new LinkedList<byte[]>();
      odebrane = new LinkedList<byte[]>();
      
      serviceURL = url;
      System.out.print("Connected with devices");

      try {
         StreamConnection connection = (StreamConnection) Connector.open(serviceURL);
         
         is = connection.openInputStream();
         os = connection.openOutputStream();
         
         System.out.println("Ok.");
         
         timer = new Timer();
         Zadanie zadanie = new Zadanie();

         timer.scheduleAtFixedRate(zadanie, 0, interval);
      } catch(IOException e) {
         e.printStackTrace();
      }
   }
   
   public void wyslij(byte[] buffer) {
      toSend.addLast(buffer);
   }
   
      
   public byte[] receive() {
      byte buffer[]= null;
      try {
         int ile;
         ile = is.available();
         
         if (ile>0) {
            buffer = new byte[2];
            is.read(buffer);
            buffer=new byte[buffer[0]];
            is.read(buffer);
            odebrane.addLast(buffer);
         }
      } catch (IOException e) {
         e.printStackTrace();
      }
      if (!odebrane.isEmpty())
         buffer = odebrane.pollFirst();
      return buffer;
   }
   
   public void wylacz() {
      timer.cancel();
   }
   
   
   class Zadanie extends TimerTask
   {
      
      public void run( )
      {
         if (is != null) {
            byte buffer[];
            try {
   //            ZAPIS
               if (!doWyslania.isEmpty()) {
                  buffer = doWyslania.pollFirst();
                  os.write(buffer.length);
                     os.write(0x00);
                     os.write(buffer);
                     os.flush();
               }
   //            ODCZYT
               //int ile = is.available();
               
               /*buffer = null;
               if (ile>0) {
                  buffer = new byte[2];
                     is.read(buffer);
                     buffer=new byte[buffer[0]];
                     is.read(buffer);
                     odebrane.addLast(buffer);
               }*/
               
               //if (ile > 0){
               //   drukuj(buffer);
               //}
               
            } catch (IOException e) {
               e.printStackTrace();
            }
         }
      }
   }

}


As you will see this code brings nothing
kspacja
New User
 
Posts: 6
Joined: Thu Nov 10, 2011 3:01 pm

Re: Temperature sensor

Postby skoehler » Wed Nov 16, 2011 4:25 pm

You don't really use leJOS, do you? I mean, there exists a leJOS PC-side API fir accessing the NXT via bluetooth.
skoehler
leJOS Team Member
 
Posts: 1114
Joined: Thu Oct 30, 2008 4:54 pm

Re: Temperature sensor

Postby kspacja » Wed Nov 16, 2011 8:36 pm

Yes, I know. I do it on purpose.
kspacja
New User
 
Posts: 6
Joined: Thu Nov 10, 2011 3:01 pm


Return to NXJ Software

Who is online

Users browsing this forum: Google [Bot] and 1 guest

more stuff