TTL camera with AltSoftSerial giving no response

I'm using a mega with 2 TTL (Adafruit) cameras. I've tested both cameras and they work independently.

Issue I ran into is I cannot use NewSoftSerial or SoftwareSerial to create more than one serial connection. I switched to AltSoftSerial but now I'm not getting any response within the Serial Monitor for either camera.

So I backed up to the AltSoftSerial example and I'm having response issues there as well. Which leads me to believe I'm doing something wrong with AltSoftSerial.

Example: For now I have one camera connected as follows, I've disconnected the second camera for testing purposes. Trying to simplify.
camera Green (RX) - AltSoftSerial TX 46
camera White (TX) - AltSoftSerial RX 48

Using the following example code

#include <AltSoftSerial.h>

// AltSoftSerial always uses these pins:
//
// Board          Transmit  Receive   PWM Unusable
// -----          --------  -------   ------------
// Arduino Mega      46        48       44, 45

AltSoftSerial altSerial;

void setup() {
  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor to open
  Serial.println("AltSoftSerial Test Begin");
  altSerial.begin(9600);
  altSerial.println("Hello World");
  Serial.println("End of Setup");
}

I get the following in the Serial Monitor

"AltSoftSerial Test Begin
End of Setup"

I don't get Hello World" and I don't get any errors.

I'd like to get the AltSoftSerial example working first before I tackle my two cameras.
I'm using Arduino IDE 1.0.5

Thank you. Let me know anything I've left out.

I'm using a mega

With 4 hardware serial ports, and no explanation as to why you need more serial ports (of the software variety).

Until you do explain, I'm going to continue to believe that you DON'T need software serial at all.

I don't believe that AltSoftSerial works on the Mega.

Understood I was wondering the same about the 4 Serial ports on a mega. I was told NewSoftSerial and the SoftwareSerial library has a restriction that you can only use one connection at a time. Hence I switched to AltSoftSerial.

How do you use 2 Serial connections on a mega with NewSoftServe? I could only get one to be successful.

void setup(){ 
Serial.begin(9600);
Serial1.begin(9600);
Serial2.begin(9600);
Serial3.begin(9600);

Serial.println("this is printed to serial 0");
Serial1.println("this is printed to serial 1");
Serial2.println("this is printed to serial 2");
Serial3.println("this is printed to serial 3");
 
}

Understood I was wondering the same about the 4 Serial ports on a mega.

The same what? You are the one electing to not use the hardware serial ports. I wonder why. You should KNOW why. If you don't, then wise up and start using them.

multiple concurrent serial connections

Let me backup a little to what lead me to my original post.

I have two adafruit TTL cameras, LCD, Data shield and a few I2C sensors on a mega.
I'm using Arduino IDE 1.0.5

I've tested each camera by themselves and they work. When I attempt to connect both to the mega and run the following code I get.

01 Camera Found:
02 Camera Found:
Failed to get 01 version
--------02 Cam---------
VC0703 1.00
Ctrl infr exist
User-defined sensor
525
Init end

#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>         

//Weather proof goes by the following
//Green RX
//White is TX

SoftwareSerial cameraconnection_01 = SoftwareSerial(50, 15); 
Adafruit_VC0706 cam_01 = Adafruit_VC0706(&cameraconnection_01);

SoftwareSerial cameraconnection_02 = SoftwareSerial(51, 17);
Adafruit_VC0706 cam_02 = Adafruit_VC0706(&cameraconnection_02);


void setup() {

  Serial.begin(9600);
   // Try to locate the camera
  if (cam_01.begin()) {
    Serial.println("01 Camera Found:");
  } else {
    Serial.println("No 01 camera found?");
  }
  if (cam_02.begin()) {
    Serial.println("02 Camera Found:");
  } else {
    Serial.println("No 02 camera found?");
  }  
  
  // Print out the camera version information
  char *reply = cam_01.getVersion();
  if (reply == 0) {
    Serial.println("Failed to get 01 version");
  } else {
    Serial.println("-------01 Cam----------");
    Serial.print(reply);
    Serial.println("-----------------");
  }
    // Print out the camera version information
  reply = cam_02.getVersion();
  if (reply == 0) {
    Serial.println("Failed to get 02 version");
  } else {
    Serial.println("--------02 Cam---------");
    Serial.print(reply);
    Serial.println("-----------------");
  }

}

void loop() {
 

}

At this point, I was advised SoftwareSerial "If using multiple software serial ports, only one can receive data at a time." or 'able to communicate'.

So I tried AltSoftSerial as I noted in my first post.

So how about you give it a go now with hardware serial and see how it goes.

When I replace SoftwareSerial in the above code with HardwareSerial I get a compile error "no matching function for call to 'HardwareSerial::HardwareSerial(int, int)'

OK bear with me I'll download the adafruit library and see if I can get to the bottom of it.

OK Well I've found that the library files are absolutely riddled with unreasonable dependencies on software serial. Even though there needn't be.

I've done some pretty extensive editing and managed to get your example to compile against my version of the Adafruit_VC0706.h library. I have no hardware to test this on though.

If you'd like to try this out I'll upload the library files (and your modified sketch) here for you to try.

OK Well I've found that the library files are absolutely riddled with unreasonable dependencies on software serial. Even though there needn't be.

I suspect that, like the Arduino process, Adafruit accepts libraries from less-than-professional programmers. I find it difficult to believe that, as good as their products and libraries usually are, that they developed this library that way.

It was nice of you to investigate, and develop a fix. How are you removing the dependency? By having the user provide the soft or hard serial instance to use?

PaulS:
It was nice of you to investigate, and develop a fix. How are you removing the dependency? By having the user provide the soft or hard serial instance to use?

I''m not sure that my solution is the ideal. It does mean that using a mega2560, it will remove any option of using softwareSerial.

Here's just one example of what I mean about the unnecessary dependency issue. When this runs, if you're using hardwareSerial, all should all be well EXCEPT it just won't compile unless you have the softwareSerial library present. (this is exactly as it comes)

void Adafruit_VC0706::sendCommand(uint8_t cmd, uint8_t args[] = 0, uint8_t argn = 0) {
  if(swSerial) {
#if ARDUINO >= 100
    swSerial->write((byte)0x56);
    swSerial->write((byte)serialNum);
    swSerial->write((byte)cmd);

    for (uint8_t i=0; i<argn; i++) {
      swSerial->write((byte)args[i]);
      //Serial.print(" 0x");
      //Serial.print(args[i], HEX);
    }
#else
    swSerial->print(0x56, BYTE);
    swSerial->print(serialNum, BYTE);
    swSerial->print(cmd, BYTE);

    for (uint8_t i=0; i<argn; i++) {
      swSerial->print(args[i], BYTE);
      //Serial.print(" 0x");
      //Serial.print(args[i], HEX);
    }
#endif
  } else {
#if ARDUINO >= 100
    hwSerial->write((byte)0x56);
    hwSerial->write((byte)serialNum);
    hwSerial->write((byte)cmd);

    for (uint8_t i=0; i<argn; i++) {
      hwSerial->write((byte)args[i]);
      //Serial.print(" 0x");
      //Serial.print(args[i], HEX);
    }
#else
    hwSerial->print(0x56, BYTE);
    hwSerial->print(serialNum, BYTE);
    hwSerial->print(cmd, BYTE);

    for (uint8_t i=0; i<argn; i++) {
      hwSerial->print(args[i], BYTE);
      //Serial.print(" 0x");
      //Serial.print(args[i], HEX);
    }
#endif
  }
}

So for this I've just added in front of it

#if defined(__AVR_ATmega2560__)
void Adafruit_VC0706::sendCommand(uint8_t cmd, uint8_t args[] = 0, uint8_t argn = 0) {

hwSerial->write((byte)0x56);
hwSerial->write((byte)serialNum);
    hwSerial->write((byte)cmd);
    for (uint8_t i=0; i<argn; i++) {
      hwSerial->write((byte)args[i]);
    }
}
#else ....

Personally, if I had more time to work on it, I'd be inclined to make an abstract class to handle the serial and make the rest of the library much cleaner. This would make it easier to include or leave out the softwareSerial as the user sees fit.

I'd be inclined to make an abstract class to handle the serial and make the rest of the library much cleaner.

Both HardwareSerial and SoftwareSerial derive from Stream, and provide the same functionality (though in very different ways). If the Adafruit_VC0706 class to a pointer to the instance of HardwareSerial or SoftwareSerial to write to, it would not be necessary to know which derived class the pointer pointed to.

KenF:
I've done some pretty extensive editing and managed to get your example to compile against my version of the Adafruit_VC0706.h library. I have no hardware to test this on though.

If you'd like to try this out I'll upload the library files (and your modified sketch) here for you to try.

KenF Wow I'm grateful for your time and effort! Absolutely I'd like to try the updated files and sample sketch.
At the end of the day, this is for a middle school science project using Infragram.org 'infrablue' images on one camera and standard color images on a second camera.

Bucky99:
KenF Wow I'm grateful for your time and effort! Absolutely I'd like to try the updated files and sample sketch.
At the end of the day, this is for a middle school science project using Infragram.org 'infrablue' images on one camera and standard color images on a second camera.

OK. I've also made copies of the examples that came with the original libraries. modified to work with the mega. (using serial only)

Bear with me, I'll Just rename the library files zip them up and find somewhere to upload. But like I say, I haven't got any hardware to test this on.

PaulS:
Both HardwareSerial and SoftwareSerial derive from Stream, and provide the same functionality (though in very different ways). If the Adafruit_VC0706 class to a pointer to the instance of HardwareSerial or SoftwareSerial to write to, it would not be necessary to know which derived class the pointer pointed to.

This is my thoughts exactly. Unfortunately, as it stands, there are three different constructors. They all include pointers to different types. A bit of cross casting, with perhaps an extra parameter to denote the actual type being passed, could overcome the issue.

Maybe later.

KenF:
Bear with me, I'll Just rename the library files zip them up and find somewhere to upload. But like I say, I haven't got any hardware to test this on.

No Problem - I'll test - I have the hardware to test on.

OK Here are the modded library files. I've renamed them MegaVC0706 so that you can keep your existing libraries without any conflict.

If you install them properly, you should be able to find the examples from the IDE MEGAMotionDetect and MEGASnapshot.

MegaVC0706.zip (12.1 KB)

By the way, you realise you'll have to use the pins that are used for the Serial1 (instead of your software serial ones) Serial 1 uses pin 18 for tx pin 19 for rx

Here's the example code you posted earlier with the modifications to suit.

#include <MegaVC0706.h>
#include <SD.h>

Adafruit_VC0706 cam_01 = Adafruit_VC0706(&Serial1);  //Pin 18 TX  Pin 19= RX
Adafruit_VC0706 cam_02 = Adafruit_VC0706(&Serial2);  //Pin 16 TX  Pin 17= RX
#define chipSelect 53

void setup() {
pinMode(chipSelect, OUTPUT); // SS 

  Serial.begin(9600);
   // Try to locate the camera
  if (cam_01.begin()) {
    Serial.println("01 Camera Found:");
  } else {
    Serial.println("No 01 camera found?");
  }
  if (cam_02.begin()) {
    Serial.println("02 Camera Found:");
  } else {
    Serial.println("No 02 camera found?");
  }  
  
  // Print out the camera version information
  char *reply = cam_01.getVersion();
  if (reply == 0) {
    Serial.println("Failed to get 01 version");
  } else {
    Serial.println("-------01 Cam----------");
    Serial.print(reply);
    Serial.println("-----------------");
  }
    // Print out the camera version information
  reply = cam_02.getVersion();
  if (reply == 0) {
    Serial.println("Failed to get 02 version");
  } else {
    Serial.println("--------02 Cam---------");
    Serial.print(reply);
    Serial.println("-----------------");
  }

}

void loop() {
}