Hi,
I am trying to interface Arduino mega with the following ultrasonic sensor module pga460-q1 . I tried to read the distance by UART but nothing helps. I tried their official energia library which is ported for arduino (PGA460EnergiaLibrary_v1.0.9_Arduino.zip attached) , but I always get the error which states that the sensor is not found. I also tried the following code
//note: minimum requirement example used to send a burst/listen command to PGA460
//cmd 0 - p1 burst listen
byte buf0[4] = {0x55, 0x00, 0x01, 0xFE};
//cmd 1 - p2 burst listen
byte buf1[4] = {0x55, 0x01, 0x01, 0xFD};
//cmd 5 - ultrasonic measurement (assume UART_ADDR=0)
byte buf5[3] = {0x55, 0x05, 0xFA}; //change
//cmd 10 - register write decple to time of 4.096ms
byte buf10[5] = {0x55, 0x0A, 0x26, 0x00, 0xCF};
//cmd 17 - broadcast p1 burst listen
byte buf17[4] = {0x55, 0x11, 0x01, 0xED};
//cmd 19 - broadcast p1 listen only
byte buf19[4] = {0x55, 0x13, 0x01, 0xEB};
//cmd 25 - broadcast bulk threshold write
byte buf25[35] = {0x55, 0x19, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x84, 0x21, 0x08, 0x42, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x84, 0x21, 0x08, 0x42, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x7C};
//byte buf00[6]={0x00,0x00,0x00,0x00,0x00,0x00};
//byte data[6]= {0x00,0x00,0x00,0x00,0x00,0x00};
const int buttonPin = 1; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
delay(1000);
// put your setup code here, to run once:
Serial.begin(19200);
Serial1.begin(19200,SERIAL_8N2); // initialize PGA460 UART serial channel
delay(1000);
//assume UART_ADDR=0
//bulk threshold write mid-code values to clear THR_CRC_ERR
Serial1.write(buf25, sizeof(buf25));
delay(100);
// set UART_ADDR=0's time decouple to 4.096ms
Serial1.write(buf10, sizeof(buf10));
delay(100);
}
void loop() {
// put your main code here, to run repeatedly:
// check if the pushbutton is pressed.
//while (digitalRead(buttonPin) == LOW){}
// broadcast p1 burst+listen (non-dependent on UART_ADDR)
Serial1.write(buf17, sizeof(buf17));
// delay by 100ms
delay(100);
//[TODO] print ultrasonic measurement results on terminal
// read back ultrasonic meas results from UART_ADDR=0
Serial1.write(buf5, sizeof(buf5));//Serial1
/* for (int i=0 ;i<=5;i++)
{
buf00[i] = Serial1.read();
}*/
/* for (int i=0 ;i<=5;i++)
{
data[i] = Serial1.read();
}*/
//SerialUSB.write(data,sizeof(data));
Serial.println(Serial1.read());
// toggle red LED
digitalWrite(ledPin, !(digitalRead(ledPin))); // turn the LED on (HIGH is the voltage level)
// repeat loop every second
delay (1000);
}
But nothing works .
To be noted I am using 2 stop bit UART , I did a voltage divider to convert my arduino voltage from 5V (Arduino mega TX) to 3.3V (module RX) , , also pulled down the SCK so that it is not floating, Any one please help!!
PGA460_USSC.cpp (102 KB)
PGA460_USSC.h (3.09 KB)
Revision_Notes.txt (1.83 KB)