Go Down

Topic: TTL camera with AltSoftSerial giving no response (Read 4705 times) previous topic - next topic

Bucky99

Nov 15, 2014, 12:02 am Last Edit: Nov 15, 2014, 12:19 am by Bucky99
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
Code: [Select]
#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.

PaulS

Quote
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.
The art of getting good answers lies in asking good questions.

Bucky99

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.

KenF

Code: [Select]

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");
 
}


PaulS

Quote
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.
The art of getting good answers lies in asking good questions.


Bucky99

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
-----------------

Code: [Select]
#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.

KenF

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

Bucky99

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)'

KenF

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

KenF

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.

PaulS


Quote
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?
The art of getting good answers lies in asking good questions.

KenF

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)
Code: [Select]

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
Code: [Select]

#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.


PaulS

Quote
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.

The art of getting good answers lies in asking good questions.

Bucky99

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.

Go Up