LinkSprite Camera with TTL Serial

Hi,
I am trying to get the LinkSprite Camera with TTL Serial to work.
I start by sending the reset command (56 00 26 00 HEX), but all I can get back is 76 HEX the correct return should be 76 00 26 00 HEX.
I am using a 5V supply.
I am not sure why I only get the 76 HEX returned? has anybody used this camera?
I have attached some of my code below.
Thanks

TCPClient client;
byte server[] = { 192, 168, 0, 8 };
byte incomingbyte;

void setup() {
Serial1.begin(38400);
delay(10);

pinMode(D0, INPUT_PULLDOWN);

}

void loop() {
if (digitalRead(D0) == HIGH)
{
if (client.connect(server, 9090))
{
client.println(“T8 SEND RESET: “);
SendResetCmd();
while(1)
{
while(Serial1.available()>0)
{
incomingbyte=Serial1.read();
client.println(incomingbyte, HEX);
}
client.println(”-”);
delay(1000);
}
}
}
}

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

Have you tried the cam without the TCPClient?
As there is a bug in TCPClient - which several threads in this forum talk about.

Hi,
I have seen threads about issues with the TCPClient, I have tried testing using spark variables and still only seem to get 1 byte 76 HEX returned?

I just noticed your

while(1)
{
  ...
}

This might be another reason for your problem - see https://community.spark.io/t/known-issue-long-delays-or-blocking-code-kills-the-connection-to-the-cloud/950

When you want to use :spark: variables, you’ll need to keep the cloud connection alive.

Have you tried to relay the incoming bytes to Serial and catch them via USB on you PC?
But still try to avoid long running loop() - which might be difficult, when reading 640x400 images at 38400 baud.

1 Like

As @ScruffR pointed out… at this time you cannot block the main loop(); Give this a try :wink:

TCPClient client;

byte server[] = {
	192, 168, 0, 8
};
byte incomingbyte;
bool hasStarted = false;

void setup() {
	Serial1.begin(38400);
	delay(10);

	pinMode(D0, INPUT_PULLDOWN);
}

void loop() {
	if (hasStarted) {
		while (Serial1.available() > 0) {
			incomingbyte = Serial1.read();
			client.println(incomingbyte, HEX);
		}
		client.println("-");
		delay(1000);
	}
	else if (digitalRead(D0) == HIGH) {
		if (client.connect(server, 9090)) {
			client.println("T8 SEND RESET: ");
			SendResetCmd();
			hasStarted = true;
		}
	}
}

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

The above suggestion is good but unfortunately will not work reliably. The current Serial1 code uses only polled IO, meaning you must be able to read the USART receive data register at least as fast as bytes are received at the serial baud rate. At 38400 bps, that means you must call Serial1.Receive() every 0.24 milliseconds. This is impossible because the code includes delay(), and (I believe) the rate at which loop() is not deterministic with delays of at least a few ms.

There’s a little more information in the thread here: https://community.spark.io/t/how-to-implement-a-2nd-tx-rx-port-bugfix/1358/18

Hi,
So how do I read from the serial1 port? I assume for Serial1.Receive() you mean Serial1.Read()?
What about the serial buffer?
You seem to imply it is never going to work from the Spark?

Not never - on the backlog there is an improvement to Serial1 that will fix this bug, just haven’t gotten to it quite yet.

ok,
Also had an issue with the TCPClient which I think is also being looked at.
Where do I look to find updates to bugs? how does the Spark get updated?
Thanks

Has anyone worked with this camera previously? I managed to get my hands on one in a bit to have a simple tutorial for the Security Camera that was shown during kickstarter.

The code is working since on Arduino after some changes as the old code given has some issues.

Printing fine on serial but the software given to try taking a snapshot and display isn’t working.

Anyone managed to do so previously? Just want to make sure the camera is ok before i switch over to the :spark: :smiley:

Ah i managed to move one step ahead but there seems to be some issue with getting a non-corrupted picture

One picture takes ~ 140 seconds to send the data over serial. :cry:

My best photo taken so far!

Anyone with any inputs? :slight_smile:

3 Likes

Hmm - interesting that the issues are only on the top chunk. Not sure what’s going on but happy to help work through it.

A few questions for debugging:

  • What speed are you running Serial?
  • Are you doing anything else at the same time?

@zach I’m using the default at 38400 on the software serial to the Camera and 19200 to the PC.

Sorry i forgot to mention i’m on the arduino as i yet to copy over to :spark:

Just want to make sure things are all working before i do the porting over and know the :spark: isn’t the issue :smiley:

Also, does the camera actually store the entire picture content and transmit? Like snap, store content, send to serial. It’s taking too long just to get one photo and i would like to make it faster! :smiley:

Kennethlimcp, software serial is notorious for not working well. It uses interrupts for receiving data so at higher baud rates, it can really bog things down. The worst though is when it sends, to get the timing right, it disables ALL interrupts while it puts out a fill 10 bits per byte of data. If you have an arduino mega or Leonardo, they have two or more hardware serial ports that are more suitable to the task. :smile:

Maybe it’s better to work from the :spark: core directly? :slight_smile:

Is Serial and Serial1 both hardware uart? Just want to make sure! :slight_smile:

:smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley:

The :spark: core just just awesome as ever! Had a tough time trying to make sure things were working well on Arduino before the port over.

BUT it turns out that porting over immediately and test turns out to be much better with a more capable :spark:!

By Arduino UNO:

BY :spark: core

Badly need my sleep at 1.05am X_X

7 Likes

Awesome! Looking forward to more of this.

Nice Core Selfie! :slight_smile:

1 Like

Looks good! How long did it take to transfer when you used the Spark Core as opposed to the Arduino?