how to get coordinate from mini rx to arduino

Frequent questions asked online, offline, in forums are answered here
Post Reply
yeni riska
Posts: 4
Joined: Thu Feb 18, 2021 4:29 pm

how to get coordinate from mini rx to arduino

Post by yeni riska »

hello..
I using dashboard v6.240 and using indoor GPS sterter kit IA-02-3D which consisting of :
4 pcs beacons hw 4.9 as stationary beacons with different frequency
1 mini rx beacon as a hedgehog (mobile beacon)
1 modem.
i have been wiring mini rx to arduino uno using "USB to TTL pl2303 module" to convert d+ d- data to rx tx data
i want to get x, y, z coordinates from mini rx to arduino using serial communication UART. but the result is :
x = 0,00000 y = 0,00000 z = 0,00000 (in freeze condition)
x = 0,00000 y = 0,00000 z = 0,00000
x = 0,00000 y = 0,00000 z = 0,00000
x = 0,00000 y = 0,00000 z = 0,00000
x = 0,00000 y = 0,00000 z = 0,00000 (in unfreeze condition)
x = 0,00000 y = 0,00000 z = 0,00000
x = 0,00000 y = 0,00000 z = 0,00000
x = 0,00000 y = 0,00000 z = 0,00000
how to solve it? is there anything i missed? i have change from uno to mega too but didn't change anything. Thank you in advance

btw, this is my arduino code :

long hedgehog_x, hedgehog_y;// coordinates of hedgehog (X,Y), mm
long hedgehog_h;// height of hedgehog, mm
int hedgehog_pos_updated;// flag of new data from hedgehog received
//#include <SoftwareSerial.h>

#include <AltSoftSerial.h>
AltSoftSerial altSerial (9,8,1);
#define HEDGEHOG_BUF_SIZE 30
#define HEDGEHOG_PACKET_SIZE 23
byte hedgehog_serial_buf[HEDGEHOG_BUF_SIZE];
byte hedgehog_serial_buf_ofs;
const int hedgehog_packet_header[5]= {0xff, 0x47, 0x01, 0x00, 0x10};

typedef union {byte b[2]; unsigned int w;} uni_8x2_16;

//////////Marvelmind hedgehog support initialize////////////////////////
void setup_hedgehog()
{
Serial.begin(9600); // hedgehog transmits data on 500 kbps
altSerial.begin(9600);
hedgehog_serial_buf_ofs = 0;
hedgehog_pos_updated = 0;
}

// Marvelmind hedgehog service loop////////////
void loop_hedgehog()
{
int incoming_byte;
int total_received_in_loop;
int packet_received;

total_received_in_loop = 0;
packet_received = 0;
while(altSerial.available() > 0)
{
if (hedgehog_serial_buf_ofs>=HEDGEHOG_BUF_SIZE) break;// buffer overflow
total_received_in_loop++;
if (total_received_in_loop>100) break;// too much data without required header

incoming_byte= altSerial.read();
// check first 5 bytes for constant value
if (hedgehog_serial_buf_ofs<5)
{
if (incoming_byte != hedgehog_packet_header[hedgehog_serial_buf_ofs])
{
hedgehog_serial_buf_ofs= 0;// restart bufer fill
continue;
}
}
hedgehog_serial_buf[hedgehog_serial_buf_ofs++]= incoming_byte;
if (hedgehog_serial_buf_ofs == HEDGEHOG_PACKET_SIZE)
{// received packet with required header
packet_received= 1;
hedgehog_serial_buf_ofs= 0;// restart bufer fill
break;
}
}//end while

if (packet_received)
{
hedgehog_set_crc16(&hedgehog_serial_buf[0], HEDGEHOG_PACKET_SIZE);// calculate CRC checksum of packet
if ((hedgehog_serial_buf[HEDGEHOG_PACKET_SIZE] == 0)&&(hedgehog_serial_buf[HEDGEHOG_PACKET_SIZE+1] == 0))
{// checksum success
hedgehog_x= int(hedgehog_serial_buf[9]) + (int(hedgehog_serial_buf[10])<<8);
hedgehog_y= int(hedgehog_serial_buf[11]) + (int(hedgehog_serial_buf[12])<<8);// coordinates of hedgehog (X,Y), cm
hedgehog_h= int(hedgehog_serial_buf[13]) + (int(hedgehog_serial_buf[14])<<8);// height of hedgehog, cm (FW V3.97+)
hedgehog_pos_updated= 1;// flag of new data from hedgehog received
}
}
}//void loop_hedgehog

// Calculate CRC-16 of hedgehog packet
void hedgehog_set_crc16(byte *buf, byte size)
{uni_8x2_16 sum;
byte shift_cnt;
byte byte_cnt;

sum.w=0xffffU;

for(byte_cnt=size; byte_cnt>0; byte_cnt--)
{
sum.w=(unsigned int) ((sum.w/256U)*256U + ((sum.w%256U)^(buf[size-byte_cnt])));

for(shift_cnt=0; shift_cnt<8; shift_cnt++)
{
if((sum.w&0x1)==1) sum.w=(unsigned int)((sum.w>>1)^0xa001U);
else sum.w>>=1;
}
}

buf[size] = sum.b[0];
buf[size+1]= sum.b[1];// little endian
}// hedgehog_set_crc16

// END OF MARVELMIND HEDGEHOG RELATED PART
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

void setup()
{
//pinMode(10, INPUT);
//#define SP2_RX 10
//#define SP2_TX 11
Serial.begin(9600);
altSerial.begin(9600);
setup_hedgehog();//Marvelmind hedgehog support initialize
}

void loop()
{
loop_hedgehog();// Marvelmind hedgehog service loop

if ( hedgehog_pos_updated );
{
hedgehog_pos_updated=0; // clear new data flag

//hedgehog_x= altSerial.read();
//hedgehog_y= altSerial.read();
//hedgehog_h= altSerial.read();

Serial.print("X=");
Serial.print(hedgehog_x*0.01,DEC );
Serial.print(" ");

Serial.print("Y=");
Serial.print(hedgehog_y*0.01,DEC );
Serial.print(" ");

Serial.print("H=");
Serial.print(hedgehog_h*0.01,DEC );
Serial.print(" \n");
}
}
Attachments
wiring mini rx to arduino
wiring mini rx to arduino
dashboard interface
dashboard interface

smoker77
Posts: 367
Joined: Sat Feb 06, 2016 4:03 pm

Re: how to get coordinate from mini rx to arduino

Post by smoker77 »

Hello,

It seems you are trying not right way for connecting mini-Rx to Arduino.
PL2303 can be used for connecting of UART to USB host, for example you can connect your Arduino's UART to PC through this module USB-TTL.
But from your photo I see you have connected mini-Rx USB to the USB side of the USB-TTL module.
This should not work because mini-Rx acts as USB device, not as host.

Mini-Rx has onboard UART which can be connected directly to Arduino, but the connector is not soldered on the board.
You can purchase this connector with the cable and solder it:
https://marvelmind.com/product/uart/

Post Reply