Completely lost... LSY201 not working with YUN

I have bough several LinkSprite LSY201 TTL camera’s and I’m trying to get them to work on my YUN.

The sample code that came with the LinkSprite used the NewSerial library, I have modified that to use the latest SoftwareSerial (otherwise the script does not compile). I’ve also removed all the “,BYTE” references (since the print command does not support that anymore). I’ve ended up with this:

#include <SoftwareSerial.h>
 
byte incomingbyte;
SoftwareSerial mySerial(10,11);                     //Configure pin 10 and 11 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.print(0x56);
      mySerial.print(0x00);
      mySerial.print(0x26);
      mySerial.print(0x00);
}
 
//Send take picture command
void SendTakePhotoCmd()
{
      mySerial.print(0x56);
      mySerial.print(0x00);
      mySerial.print(0x36);
      mySerial.print(0x01);
      mySerial.print(0x00);  
}
 
//Read data
void SendReadDataCmd()
{
      MH=a/0x100;
      ML=a%0x100;
      mySerial.print(0x56);
      mySerial.print(0x00);
      mySerial.print(0x32);
      mySerial.print(0x0c);
      mySerial.print(0x00); 
      mySerial.print(0x0a);
      mySerial.print(0x00);
      mySerial.print(0x00);
      mySerial.print(MH);
      mySerial.print(ML);   
      mySerial.print(0x00);
      mySerial.print(0x00);
      mySerial.print(0x00);
      mySerial.print(0x20);
      mySerial.print(0x00);  
      mySerial.print(0x0a);
      a+=0x20;                            //address increases 32,set according to buffer size
}
 
void StopTakePhotoCmd()
{
      mySerial.print(0x56);
      mySerial.print(0x00);
      mySerial.print(0x36);
      mySerial.print(0x01);
      mySerial.print(0x03);        
}

I know not all the digital ports on the Yun are usable, so I’ve modified the source code to use pins 10 and 11.

What happens is… well… nothing! I get nothing but empty lines on the Serial output, indicating that the LSY201 returns nothing at all. I’ve tried with several other camera’s, same problem… 5V, ground and both RX and TX pins are connected to the camera.

Is there a known problem with SoftwareSerial and the Yun? What am I missing here???

wimpie3:
I have bough several LinkSprite LSY201 TTL camera's and I'm trying to get them to work on my YUN.

::::SNIP::::

Is there a known problem with SoftwareSerial and the Yun? What am I missing here???

wimpie3,
You may have a pin conflict. Below are two reference pages. Someone will come along in a bit with more information.
Jesse

:: Shield Pin Usage ::
http://playground.arduino.cc/Main/ShieldPinUsage

Arduino Yún

scroll down to Input and Output

A pin conflict? But I’m not using a shield! Just a bare Yun. I’ve tried other PIN combinations as well, other baudrates… no data is returned…

Can you try the camera with a common arduino? (Arduino uno for example)

wimpie3:
5V, ground and both RX and TX pins are connected to the camera.

Just a thought... are you powering the camera by connecting it to the 5V pin on the Yun? There is a blocking diode there to prevent back-feeding power into that pin, which means the actual output voltage is really only about 4.5 volts. Might that not be enough voltage for the camera? Might the camera be trying to draw too much current? Do you have a separate 5V supply you can use for the camera? (Still connect the 5V supply ground to the Yun ground.)

And pardon me if this is too obvious, but is there any chance you have Txt/Rx backwards? (Tx should go to Rx; Rx to Tx)

Do you have a scope or other test instrument that can check if there is any data being sent? (If nothing else, connect an LED with an approximately 1k resistor from 5V to the serial data pin and see if it flickers.)

To test if the software serial works, and to eliminate a variable, try writing a simple loopback test sketch: write a sketch that sends with software serial, reads with software serial, and writes what was written to the regular Serial port. Then with nothing else connected, jumper the Rx and Tx lines together, and you should see your data on the regular Serial port. Something like this (i have not compiled or tested this):

void loop()
{
  mySerial.write('a');
  if (mySerial.available())
  {
    char ch = mySerial.read();
     Serial.write(ch);
  }
}

I’ve used a loopback sketch (Serial1 <-> Serial) to see what’s going on and to rule out problems with the software serial.

  1. There is lot of “noise” (random characters dumped), even when the RX & TX & 5v to the camera are not connected. Is this normal?

  2. When I connect the camera to 5V and RX/TX to pins 0 & 1, the random characters continue.

  3. BUT… a breakthrough, as soon as I remove PIN 1 and only keep the INCOMING line, I can see the camera responding!

So two questions here: why is there noise on the serial line, and why can I receive info from the camera when the send pin (pin 1) is disconnected. A power problem??

Pins 0 and 1 on the Yun are dedicated for Bridge communications to the AR3391 processor running OpenWRT. You can't use those pins for anything else. You are probably getting your noise because of interference with the data coming from the OpenWRT side.

You MUST use other pins, not 0 or 1. I also would not use 13, as that has an LED on it, loading down the line somewhat.

So you're actually saying that Serial1 (hardware serial) is unusable on the Yun?? Yun has no hardware serial?

wimpie3:
So you’re actually saying that Serial1 (hardware serial) is unusable on the Yun?? Yun has no hardware serial?

Sad but true.

I’d use a webcam connected to Yun USB.

wimpie3:
So you're actually saying that Serial1 (hardware serial) is unusable on the Yun?? Yun has no hardware serial?

No, that's not what I'm saying. Serial1 is quite usable, but ONLY for talking to the AR3391 processor. You can't use it for other purposes, like talking to external hardware.

(Actually, there is a rather convoluted way you can free up the pins, by playing with GPIO23 on the AR3391 processor, but then you lose the Bridge features and the inter-processor communications, defeating much of the appeal of the Yun.)

ShapeShifter:
No, that's not what I'm saying. Serial1 is quite usable, but ONLY for talking to the AR3391 processor. You can't use it for other purposes, like talking to external hardware.

::::SNIP::::

@ShapeShifter, what about bit-banging on pins 2 & 3? could that be an option for wimpie3?
It's a bit processor intensive and could be painful considering he is using a Camera.

Just a thought
Jesse

jessemonroy650:
@ShapeShifter, what about bit-banging on pins 2 & 3? could that be an option for wimpie3?

Actually, with his use of SoftwareSerial, that's what I thought he was doing all along on pins 10 and 11.

ShapeShifter:
Actually, with his use of SoftwareSerial, that's what I thought he was doing all along on pins 10 and 11.

Yeah, I guess. But assume that pins 0 & 1 had a shift register...
The truth is I just don't know. I'm not a hardware person... Just throwing out ideas.

Jesse

jessemonroy650:
Yeah, I guess. But assume that pins 0 & 1 had a shift register...

Yes, 0&1 have UART hardware behind it, so it's faster and MUCH more efficient. SoftwareSerial bit-bangs the interface, so it's a lot slower, but works on (almost) any pair of pins.

The (almost) is because of this note on the SoftwareSerial page (the Yun's Arduino side is functionally the same as a Leonardo):

  • Not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

With the OP's use of pins 10 and 11, this should not be a problem:

SoftwareSerial mySerial(10,11);                     //Configure pin 10 and 11 as soft serial port

I can get the camera to work on pins 0 & 1 (with the garbage bytes included), but as soon as I switch to SoftwareSerial, nope, doesn't work, all garbage and not one single recognizable character. I have the impression that SoftwareSerial simply does not work on the Yun. And the hardware serial cannot be used either, so I'm stuck!

wimpie3:
as soon as I switch to SoftwareSerial, nope, doesn’t work, all garbage and not one single recognizable character. I have the impression that SoftwareSerial simply does not work on the Yun.

If you are getting garbage characters, that’s usually an indication of an incorrect baud rate, not necessarily that it won’t work with the Yun.

Did you try the SoftwareSerial loopback test I mentioned? If that works, the SoftwareSerial works, and you’ve got baud rate or hardware issues. When I brought that up last time, you wrote this:

wimpie3:
I’ve used a loopback sketch (Serial1 <-> Serial) to see what’s going on and to rule out problems with the software serial.

That’s not what I’m talking about, that is shuffling data between the USB serial and the hardware serial going to the AR3391 OpenWRT processor.

I tried a quick loopback test, with pins 10 and 11 shorted together:

#include "SoftwareSerial.h"

SoftwareSerial mySerial(10, 11);

const char data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i;

void setup()
{
  Serial.begin(115200);
  mySerial.begin(38400);
  
  // Wait until a Serial Monitor is connected.
  while (!Serial);

  Serial.println("SoftwareSerial loopback test");
  
  i = 0;
  
  mySerial.listen();
}

void loop()
{
  // A little delay to allow the 'scope to trigger
  delay(1);
  
  // Output the current character of the pattern
  mySerial.write(data[i]);
  
  // Is there incoming data?
  if (mySerial.available())
  {
    // Read the incoming data and send it out the serial port
    char ch = mySerial.read();
    Serial.write(ch);
  }
  else
    Serial.print('.');
  
  // Advance to the next pattern character, wrap if done.
  i++;
  if (i>= sizeof(data))
    i = 0;
}

Using an oscilloscope, I have verified that data is getting transmitted, but I never get anything back. I thought adding the listen() call might help, but it makes no difference. This same code also returns nothing on an Uno.

I tried the standard SoftwareSerial example on my Uno. I get garbage on the serial monitor.

This does not appear to be a problem that's specific to the Yun, I can't get it to work on the Uno, either. This appears to be a general SoftwareSerial problem? Or more likely an operator error on my part...

Unfortunately, I don't have more time to look into this now. But knowing that it's not a Yun-specific problem might allow you to widen your search for a solution?

wimpie3:
I can get the camera to work on pins 0 & 1 (with the garbage bytes included), but as soon as I switch to SoftwareSerial, nope, doesn't work, all garbage and not one single recognizable character. I have the impression that SoftwareSerial simply does not work on the Yun. And the hardware serial cannot be used either, so I'm stuck!

wimpie3,
I had a crazy idea. Did you set the pins to Digital, and Did you set them to input & output - respectively?
I did not see that in your code.

Just an idea.
Jesse

jessemonroy650:
I had a crazy idea. Did you set the pins to Digital, and Did you set them to input & output - respectively?

I don't think that's an issue.

I didn't do it my quick test, nor is it done in any of the official SoftwareSerial examples. Looking at the code in SoftwareSerial.cpp, it does explicitly set the pin modes to input and output.

Did a check with setting the pins to input & output, no difference.

So... uhmmm... H-E-L-P! I don't know what to do next. Can anyone report this as a bug, escalate this to Arduino, call Obama, or whatever? :slight_smile: I'm a newbie, I haven't got a clue on what to do next.