LinkSprite Infrared JPEG TTL Camera Not Working


#1

I recently got the LinkSprite Infrared JPEG camera (linked here) and it doesn’t seem to work at all with the RedBear Duo. I’ve tried implementing the given Arduino code (see link under “Documents” for original code) with a few minor changes to be compatible with the RBDuo. I started off by adding this snippet:

#if defined(ARDUINO) 
SYSTEM_MODE(MANUAL); 
#endif

I also am not using SoftwareSerial.h so I commented those 2 lines out. The SoftwareSerial.h library doesn’t seem to work with the Duo (getting many compilation errors) so I had to switch to using the built-in “Serial1” object to communicate with the camera via the actual RX, TX pins which are on pins D16 and D17 respectively (note that the RX camera pin is hardwired to the TX RBDuo pin and vice versa). Here is the full modified Arduino code:

/****************************************************************************** 
LinkSprite_Cam
Ryan Owens @ SparkFun Electronics>
Revised by Joel Bartlett on 03/25/15 for compilation on Arduino 1.6+

This code allows you to control the LinkSprite IR Camera (SEN-11610) with an Arduino microcontroller

Development environment specifics:
Arduino 1.6.0

This code is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round!

Distributed as-is; no warranty is given. 
*********************************************************************************/
//#include <SoftwareSerial.h> //Library not compatible with Redbear Duo

#if defined(ARDUINO) 
SYSTEM_MODE(MANUAL); 
#endif

/* Linksprite */
byte incomingbyte;
//SoftwareSerial Serial1(7, 8); // RX, TX         //Using hardwired RX,TX pins (D16,D17) on RBDuo

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(9600);
  Serial1.begin(38400);
}

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

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

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

         delay(25);
          while(Serial1.available()>0)
          {
               incomingbyte=Serial1.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()
{
      Serial1.write(0x56);
      Serial1.write((byte)0);
      Serial1.write(0x26);
      Serial1.write((byte)0);
}

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

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

void StopTakePhotoCmd()
{
      Serial1.write(0x56);
      Serial1.write((byte)0);
      Serial1.write(0x36);
      Serial1.write(0x01);
      Serial1.write(0x03);        
}

Here are my tools settings in the Arduino IDE (v1.8.5):
image

My RedBear Duo has the latest firmware installed (v0.3.1) and when I upload the code via the Arduino IDE and open the Serial Monitor my code seems to be skipping this while loop entirely:

          while(Serial1.available()>0)
          {
               incomingbyte=Serial1.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++;
               }
          }

I know this because the print statement at the end of the outer while loop is endlessly printing new lines in the console and the flag is never set to 1 (high --> indicating exit on outer while loop), so for some reason Serial1 is never available.

One potential issue could be the baudrates which I set to 9600 for “Serial” (RBDuo) and 38400 for “Serial1” (camera), both baudrates are default for each device. I’ve tried changing the baudrate for the camera to match the Serial baudrate of 9600 using the command given in the camera manual but nothing seems to work.

I tried running the original code (no modifications) on an Arduino Uno (both baudrates set to 38400) to check that the camera is functioning properly and I was able to capture the hex JPEG data as expected so I know for sure the camera is not the issue.

Please let me know if you can think of any solutions, working with the RB Duo and this camera has been frustrating to say the least!