Hello,
I have a project where I am reading from a LinkSprite Serial TTL Camera and saving the image to an SD card. I got this working on the UNO with an Ethernet shield. I want to move it to the MEGA 2560 to give me more room to program.
The problem is this: Every time I connect the camera to the MEGA I seem unable to receive any serial data from it. This small bit of sample code below will just hang forever (in the loop after "Waiting for camera init end") on the MEGA, but will work fine on my UNO.
I have tried several things including using SoftwareSerial on pins 50 and 51, and also using Mega's Serial2 on pins 16 and 17. It just seems to be unable to receive from the camera on the MEGA. Any explanations as to what the problem might be? Every time I switch back to the UNO it is fine...
/* Linksprite
Infrared Camera Test Code for MEGA. This is meant to be a functional test of your camera and SD card only... To be used to verify your
circuit and board before you use oap_motioncamera_mega (which is the full Ethernet Shield, Motion Detector, and camera)
As such, you don't really need any of the motion detector connections outlined below
Notes:
Not all pins on the Mega and Mega 2560 support change interrupts, so only the following
can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
*/
#include <SoftwareSerial.h>
#include <SD.h>
int sdCardControlPin = 4; // SD Card Control Pin
byte incomingbyte;
byte responseMessage[20]; // Used to hold responses
//SoftwareSerial(rxPin, txPin)
SoftwareSerial mySerial(5,6); //Configure pin (rx) and (tx) as soft serial port
// Try using MEGA serial 2 which should be: 17 (RX) and 16 (TX)
int i=0; // loop
void setup()
{
Serial.begin(9600);
//Serial2.begin(38400);
mySerial.begin(38400);
delay(25);
// if (mySerial.isListening() )
// Serial.println("Camera is listening");
// Wait for proper response from camera
Serial.println("Waiting for camera init end");
i = 0;
while(i <= 15)
{
if (mySerial.available()>0) {
incomingbyte=mySerial.read();
responseMessage[i] = incomingbyte;
Serial.print(responseMessage[i]);
i++;
}
}
// Did we get the expected response?
if (responseMessage[0] == 0x36 && responseMessage[1] == 0x32 && responseMessage[14] == 0x0A) {
Serial.println("Camera is initialized");
}
else
Serial.println("WARNING: Camera not initialized");
// Set up SD Card
pinMode(sdCardControlPin, OUTPUT);
if (!SD.begin(sdCardControlPin)) {
Serial.println(" Card failed, or not present"); // don't do anything more:
return;
}
Serial.println("SD Card initialized.");
}
void loop()
{
Serial.println("Beginning Loop");
Serial.println("Sleeping before taking another picture...");
delay(5000);
}
Thanks!
Dave