SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By mikehoover
#137690
I am working through the book "Building Wireless Sensor Networks" and am currently on Chapter Four - The Romantic Light Sensor With Feedback. I have copied the sketch from the O'Reilly website into Arduino and am trying to upload it to the Uno board. When I try to verify or upload the sketch I get plenty of errors with the setRemoteState() function. Apparently BYTE had be deprecated so the lines with
Code: Select all
Serial.print(value, BYTE);
need to be replaced with:
Code: Select all
 Serial.write(value);
.

I have made the changes but now get more errors, namely, the "call of overloaded 'write(int) is ambiguos" error, which points to several lines in the setRemoteState() function:
Code: Select all
  Serial.write(0x0); // high part of length (always zero)
  ...
  Serial.write(0x0); // frame id set to zero for no reply
  //ID of recipient, or use 0xFFFF for broadcast
  Serial.write(00);
  Serial.write(00);
  Serial.write(00);
  Serial.write(00);
  Serial.write(00);
  Serial.write(00);
The error information that appears for each occurrence is:
Code: Select all
RomanticLightFeedback.cpp: In function 'void setRemoteState(int)':
RomanticLightFeedback:122: error: call of overloaded 'write(int)' is ambiguous
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/HardwareSerial.h:58: note: candidates are: virtual size_t HardwareSerial::write(uint8_t)
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:49: note:                 size_t Print::write(const char*)
Here is the original code for the setRemoteState() function:
Code: Select all
void setRemoteState(int value) {  // pass either a 0x4 or and 0x5 to turn the pin on or off
  Serial.print(0x7E, BYTE); // start byte
  Serial.print(0x0, BYTE); // high part of length (always zero)
  Serial.print(0x10, BYTE); // low part of length (the number of bytes that follow, not including checksum)
  Serial.print(0x17, BYTE); // 0x17 is a remote AT command
  Serial.print(0x0, BYTE); // frame id set to zero for no reply
  // ID of recipient, or use 0xFFFF for broadcast
  Serial.print(00, BYTE);
  Serial.print(00, BYTE);
  Serial.print(00, BYTE);
  Serial.print(00, BYTE);
  Serial.print(00, BYTE);
  Serial.print(00, BYTE);
  Serial.print(0xFF, BYTE); // 0xFF for broadcast
  Serial.print(0xFF, BYTE); // 0xFF for broadcast
  // 16 bit of recipient or 0xFFFE if unknown
  Serial.print(0xFF, BYTE);
  Serial.print(0xFE, BYTE);
  Serial.print(0x02, BYTE); // 0x02 to apply changes immediately on remote
  // command name in ASCII characters
  Serial.print('D', BYTE);
  Serial.print('1', BYTE);
  // command data in as many bytes as needed
  Serial.print(value, BYTE);
  // checksum is all bytes after length bytes
  long sum = 0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '1' + value;
  Serial.print( 0xFF - ( sum & 0xFF) , BYTE ); // calculate the proper checksum
  delay(10); // safety pause to avoid overwhelming the serial port (if this function is not implemented properly)
}
Has anyone worked through this exercise and figured out how to make it work?

Thanks!
By TCWORLD
#137692
Change:
Code: Select all
Serial.print(00, BYTE);
to:
Code: Select all
Serial.write((byte)0x0);
That compiles fine. I believe that it is confusing 0x0 as a NULL character at the end of a string, so the compiler believes that the command will send nothing. By specifying (byte) it tells the compiler that it is a value not a string (I think that is right, either way the change definately works).
By Philba
#137702
The problem stems from the fact that the function does different things with different data types. If you pass it a character, it prints a character. If you give it an int, it converts it to the character representation of the int and prints it. If you give it a float, it prints it as you would expect to see a floating point number printed. So, you have to help it out by telling it the parameter's type.
By quique
#184671
Ok I had that same sketch and was getting those errors. I changed it and now I get these:
LinkSprite_cam_IR.ino: In function 'void SendResetCmd()':
LinkSprite_cam_IR.ino:71:26: error: call of overloaded 'write(int)' is ambiguous
LinkSprite_cam_IR.ino:71:26: note: candidates are:
In file included from LinkSprite_cam_IR.ino:3:0:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.h:100:18: note: virtual size_t SoftwareSerial::write(uint8_t)
virtual size_t write(uint8_t byte);
^
In file included from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Stream.h:26:0,
from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.h:36,
from LinkSprite_cam_IR.ino:3:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:49:12: note: size_t Print::write(const char*)
size_t write(const char *str) {
^
LinkSprite_cam_IR.ino:73:26: error: call of overloaded 'write(int)' is ambiguous
LinkSprite_cam_IR.ino:73:26: note: candidates are:
In file included from LinkSprite_cam_IR.ino:3:0:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.h:100:18: note: virtual size_t SoftwareSerial::write(uint8_t)
virtual size_t write(uint8_t byte);
^
In file included from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Stream.h:26:0,
from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.h:36,
from LinkSprite_cam_IR.ino:3:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:49:12: note: size_t Print::write(const char*)
size_t write(const char *str) {
^
Error compiling.
Here is the sketch:
Code: Select all
/* Linksprite */

#include <SoftwareSerial.h>

byte incomingbyte;
SoftwareSerial mySerial(4,5);                     //Configure pin 4 and 5 as soft serial port
int a=0x0000,j=0,k=0,count=0;                    //Read Starting address       
uint8_t MH,ML;
boolean EndFlag=0;
                               
void SendResetCmd();
void SendTakePhotoCmd();
void SendReadDataCmd();
void StopTakePhotoCmd();

void setup(){ 
  Serial.begin(19200);
  mySerial.begin(38400);
}

void loop() {
     SendResetCmd();
     delay(4000);                               //After reset, wait 2-3 second to send take picture command
      
      SendTakePhotoCmd();

     while(mySerial.available()>0)
      {
        incomingbyte=mySerial.read();

      }   
      byte a[32];
      
      while(!EndFlag)
      {  
         j=0;
         k=0;
         count=0;
         SendReadDataCmd();

         delay(25);
          while(mySerial.available()>0)
          {
               incomingbyte=mySerial.read();
               k++;
               if((k>5)&&(j<32)&&(!EndFlag))
               {
               a[j]=incomingbyte;
               if((a[j-1]==0xFF)&&(a[j]==0xD9))      //Check if the picture is over
               EndFlag=1;                           
               j++;
	       count++;
               }
          }
         
          for(j=0;j<count;j++)
          {   if(a[j]<0x10)
              Serial.print("0");
              Serial.print(a[j],HEX);
              Serial.print(" ");
          }                                       //Send jpeg picture over the serial port
          Serial.println();
      }      
     while(1);
}

//Send Reset command
void SendResetCmd()
{
      mySerial.write(0x56);
      mySerial.write(0x00);
      mySerial.write(0x26);
      mySerial.write(0x00);
}

//Send take picture command
void SendTakePhotoCmd()
{
      mySerial.write((byte)0x56);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x36);
      mySerial.write((byte)0x01);
      mySerial.write((byte)0x00);  
}

//Read data
void SendReadDataCmd()
{
      MH=a/0x100;
      ML=a%0x100;
      mySerial.write((byte)0x56);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x32);
      mySerial.write((byte)0x0c);
      mySerial.write((byte)0x00); 
      mySerial.write((byte)0x0a);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x00);
      mySerial.write(MH);
      mySerial.write(ML);   
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x20);
      mySerial.write((byte)0x00);  
      mySerial.write((byte)0x0a);
      a+=0x20;                            //address increases 32£¬set according to buffer size
}

void StopTakePhotoCmd(){
      mySerial.write((byte)0x56);
      mySerial.write((byte)0x00);
      mySerial.write((byte)0x36);
      mySerial.write((byte)0x01);
      mySerial.write((byte)0x03);        
}
By Valen
#184672
quique wrote:Ok I had that same sketch and was getting those errors. I changed it and now I get these:
LinkSprite_cam_IR.ino: In function 'void SendResetCmd()':
Compare the code in the function SendResetCmd() with the code in SendTakePhotoCmd(). Looks like you forgot something.
By quique
#184673
Yes thanks. I caught that. Unfortunately now, although it compiles, I get blank data. By that I mean the Serial Monitor scrolls up endlessly with nothing but blank spaces in it. At least with another sketch I get 00 00 00 as the data. Both sketches result in a 0 byte jpeg at the end. I dont really know how to debug 0 data coming through. Any ideas?
By Valen
#184674
Instead of the Arduino serial monitor use a serial terminal program that can show the output in hexadecimal format. Too many available on the internet to suggest a specific one. Just google for it.
By quique
#184675
I get this using Serial tools on my mac:

Ö9ÖKInitializing SD card...initialization done.
please waiting ....
incoming...0incoming...0incoming...0
incoming...0
incoming...0incoming...0
incoming...0incoming...0incoming...0
incoming...0incoming...0
incoming...0incoming...0
incoming...0incoming...0incoming...0

which is due to a serial.print I added to log the word incoming... and the byte.

Or this when I select Raw:

incoming...0<0D><0A>incoming...0<0D><0A>incoming...0incoming...0incoming...0<0D><0A><0D><0A>incoming...0incoming...0<0D><0A>incoming...0<0D><0A>incoming...0<0D><0A>
By Valen
#184676
Ehm, hold on! How can that be the same sketch as Mikehoover posted? The "Romantic Light Sensor" from that book is a lot different from a Linksprite camera that you are using. If you want help with your own code I suggest you start a new thread. It's best not to get different topics mixed up. Asking for help about that "call of overloaded 'write(int)' is ambiguous" error in here was on topic.

And when you do start a new thread, please be more detailed in what hardware you have and what the code is supposed to do. Sparkfun carries 2 different Linksprite cameras. They both send data back when you issue them a command. Your code is not paying attention to that. At the very least you send that back to your pc to help debug.