Announcement

Collapse
No announcement yet.

uCam-III with Arduino Uno(SYNC issue)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • uCam-III with Arduino Uno(SYNC issue)

    I am trying to communicate with the uCam-III using an Arduino Uno.

    My main issue is that the initial SYNC process(upon power-on) is failing.
    The pins are connected as follows:
    • Power is connected to the 5V port on the Uno
    • Ground is connected to the GND port on the Uno
    • TX is connected to the RX on the Uno
    • RX is connected to the TX on the Uno
    • Reset is connected to a digital port on the Uno and toggled through software(active low)

    In the code attached below, what I am trying to do is:
    1. Reset it using the digital pin from Uno
    2. Send it SYNC command until I receive an ACK back(or 60 tries have passed)
    3. Finalize the process by receiving a SYNC and sending a ACK back to the camera
    I am currently failing to even receive anything meaningful back from the camera.
    I have no good way/equipment of testing whether the Uno is sending what I think it is sending.
    I know that:
    • The data width is correct, because I used "Serial.begin(9600, SERIAL_8N1)". The 8N1 means 8 bit data, with no parity bit, and one stop bit, which is exactly what the camera expects.
    • The camera is being powered successfully, since we can feel the camera is a bit warm
    • The baud rate is OK, because the specification says the camera will auto detect the rate, and 9600 is one of the acceptable ones.

    I feel like I am doing exactly what the uCam-III specification says, but something is not right.
    I have searched around and found no answer that could help me.
    If anyone have a theory as to why this is not working, please feel free to say something.
    Thanks.

    For your reference, the uCam-III specification is also attached below, as a file.
    Code:
    // Compiler Linkage
    extern "C" {
      #include <stdbool.h>
      #include "commandSet.h"
    }
    // Pin Declaration
    static const int Reset = 7;
    
    /*
     * Simple Test to assess the communication
     * capability of the uCAM-III device
     * (Designed for Arduino Uno or similar hardware)
     * NOTE: It is highly recommended that the Reset pin
     *       is connected, although it is optional
     *
     * Author: Haomin Yu
     */
    void setup() {
      Serial.begin(9600, SERIAL_8N1);
      pinMode(Reset, OUTPUT);
      digitalWrite(Reset, LOW);
      delay(5);
      digitalWrite(Reset, HIGH);
      if(initializeCamera()) {
        delay(5);
        bool receivedSync = receiveSyncCommand();
        sendAckSyncCommand();
        if(receivedSync) {
          Serial.println("Initialization Successful!");
        }
        else {
          Serial.println("Received ACK but not SYNC");
        }
      }
      else {
        Serial.println("Initialization Failed!");
      }
    }
    
    void loop() {}
    Code:
    // Compiler Linkage
    extern "C" {
      #include <stdbool.h>
      #include "commandSet.h"
    }
    
    /*
     * Holds auxiliary commands necessary for testing
     * the uCAM-III device
     * (Designed for Arduino Uno or similar hardware)
     *
     * Author: Haomin Yu
     */
    
    /*
     * Initializes the uCAM-III
     * (Necessary upon power-on)
     */
    static const int MAX_SYNC_ATTEMPTS = 60;
    bool initializeCamera() {
      int syncAttempts = 0;
      bool ackReceived = false;
      do {
        sendSyncCommand();
        ackReceived = receiveAckCommand();
        delay(5 + syncAttempts++);
      } while((syncAttempts < MAX_SYNC_ATTEMPTS) && !ackReceived);
      return syncAttempts < MAX_SYNC_ATTEMPTS;
    }
    
    /*
     * Sends a SYNC command through serial
     * (With a small built-in delay)
     */
    void sendSyncCommand() {
      Serial.write(syncCommand, sizeof(syncCommand));
      delay(1);
    }
    
    /*
     * Attempts to receive a SYNC command through serial
     * (Returns false if fails)
     */
    bool receiveSyncCommand() {
      bool isSyncCommand = true;
      char incoming = 0;
      // Checking if first byte is 0xAA
      incoming = Serial.read();
      isSyncCommand = isSyncCommand && (incoming == 0xAA);
      // Checking if second byte is 0x0D
      incoming = Serial.read();
      isSyncCommand = isSyncCommand && (incoming == 0x0D);
      // Checking if third byte is 0x00
      incoming = Serial.read();
      isSyncCommand = isSyncCommand && (incoming == 0x00);
      // Checking if fourth byte is 0x00
      incoming = Serial.read();
      isSyncCommand = isSyncCommand && (incoming == 0x00);
      // Checking if fifth byte is 0x00
      incoming = Serial.read();
      isSyncCommand = isSyncCommand && (incoming == 0x00);
      // Checking if sixth byte is 0x00
      incoming = Serial.read();
      isSyncCommand = isSyncCommand && (incoming == 0x00);
      return isSyncCommand;
    }
    
    /*
     * Sends a ACK command through serial, indicating
     * that the SYNC command has been registered
     * (With a small built-in delay)
     */
    void sendAckSyncCommand() {
      Serial.write(ackSyncCommand, sizeof(ackSyncCommand));
      delay(1);
    }
    
    /*
     * Attempts to receive a ACK command through serial
     * (Returns false if fails)
     */
    bool receiveAckCommand() {
      bool isAckCommand = true;
      char incoming = 0;
      // Checking if first byte is 0xAA
      incoming = Serial.read();
      isAckCommand = isAckCommand && (incoming == 0xAA);
      // Checking if second byte is 0x0E
      incoming = Serial.read();
      isAckCommand = isAckCommand && (incoming == 0x0E);
      // Checking if third byte is 0x0D
      incoming = Serial.read();
      isAckCommand = isAckCommand && (incoming == 0x0D);
      // Throwing away fourth byte (Debugging byte)
      incoming = Serial.read();
      // Checking if fifth byte is 0x00
      incoming = Serial.read();
      isAckCommand = isAckCommand && (incoming == 0x00);
      // Checking if sixth byte is 0x00
      incoming = Serial.read();
      isAckCommand = isAckCommand && (incoming == 0x00);
      return isAckCommand;
    }
    Code:
    /*
     * This file holds the byde code which represents
     * the command set for the camera (uCAM-III)
     *
     * Author: Haomin Yu
     */
    #pragma once
    
    #ifndef _COMMANDSET_H_
    #define _COMMANDSET_H_
    
    // SYNC command
    static const char syncCommand[] = {0xAA, 0x0D, 0x00, 0x00, 0x00, 0x00};
    // ACK command for SYNC without debugging
    static const char ackSyncCommand[] = {0xAA, 0x0E, 0x0D, 0x00, 0x00, 0x00};
    
    #endif /* _COMMANDSET_H_ */
    Attached Files

  • #2
    Hello,

    This is a duplicate post.
    Please check the other thread. Thanks

    Best Regards,

    Comment


    • #3
      hello,
      it says
      commandSet.h no such file or directory exists, please guide
      thanks

      Comment


      • #4
        Dear Rashmi,

        Welcome to the forum.

        Try to check the other thread mention above. Then make sure that both files are extracted into the same folder before you upload to your Arduino.

        Thank you.

        Regards,
        Ferdinand

        Comment

        Working...
        X