Marvelmind beacons showing only zeros after connection

im trying to show the location of headhog beacons on my serial display but only 0 are showing
i switched the beacons last time and it worked but now it's back
this is my code

#include <SoftwareSerial.h>

SoftwareSerial portOne(0,1);

int hedgehog_x, hedgehog_y;// coordinates of hedgehog (X,Y), cm
int hedgehog_h;// height of hedgehog, cm
int hedgehog_pos_updated;// flag of new data from hedgehog received

///

#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(57600); // hedgehog transmits data on 500 kbps  
  portOne.begin(57600);
  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;
   portOne.listen();/////////////////////////////////////////////////////////////////////////////////

  total_received_in_loop= 0;
  packet_received= 0;
 // while(Serial.available() > 0)//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  while (portOne.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= Serial.read();
      incoming_byte= portOne.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; 
        }
    }

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

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


void setup()
{ 

  setup_hedgehog();//    Marvelmind hedgehog support initialize
  Serial.begin(57600); // to display via USB serial port
}

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

   if (hedgehog_pos_updated)
     // new data from hedgehog available
       hedgehog_pos_updated= 0;// clear new data flag 
       // output hedgehog position to LCD



Serial.print("X=");
Serial.print(hedgehog_x);
Serial.print("   ");  
       
Serial.print("Y=");
Serial.print(hedgehog_y);
Serial.print("   ");  

Serial.print("H=");
Serial.print(hedgehog_h);
Serial.print("   ");  

Serial.println();
}

6ca9ba8c2fc4cc7ca6862f85919dbf91cdccf54d_2_690x470


i tried to test the serial1 it give some output at unequal interval

/*

  Multiple Serial test

  Receives from the main serial port, sends to the others.

  Receives from serial port 1, sends to the main serial (Serial 0).

  This example works only with boards with more than one serial like Arduino Mega, Due, Zero etc.

  The circuit:

  - any serial device attached to Serial port 1

  - Serial Monitor open on Serial port 0

  created 30 Dec 2008

  modified 20 May 2012

  by Tom Igoe & Jed Roach

  modified 27 Nov 2015

  by Arturo Guadalupi

  This example code is in the public domain.

*/

void setup() {

  // initialize both serial ports:

  Serial.begin(9600);

  Serial1.begin(9600);
}

void loop() {

  // read from port 1, send to port 0:

  if (Serial1.available()) {

    int inByte = Serial1.read();

    Serial.write(inByte);
    Serial.println(inByte);

  }

  // read from port 0, send to port 1:

  if (Serial.available()) {

    int inByte = Serial.read();

    Serial1.write(inByte);

  }
}

Hi,
Its prefered that you don't use pins 0 and 1, as the yare the programming pins, they are also used when yo u use serial monitor.

Can you please post the data/specs on the "hedgehog"?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

thank you for answering Tom
i have changed the serial port to serial1
as follow

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

//AltSoftSerial altSerial(9, 8, 1);//rx tx
#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);

  Serial1.begin(9600);
    //Serial1.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(Serial1.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= Serial1.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///
//SoftwareSerial mySerial(10, 11); //RX and TX
void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
  setup_hedgehog();//Marvelmind hedgehog support initialize
  //altSerial(10, 9);
  //Serial1.begin(9600);
  //Serial1(19, 18, 1);//RX and TX and inverting logic
  //Serial2.begin(9600);
}

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

   if (hedgehog_pos_updated);
     {
          hedgehog_pos_updated=0;

          //hedgehog_x= altSerial.read();
          //hedgehog_y= altSerial.read();
          //hedgehog_h= altSerial.read();
          
          Serial1.print("X=");
          Serial1.print(hedgehog_x*0.01, DEC );
          Serial1.print(" ");  
                 
          Serial1.print("Y=");
          Serial1.print(hedgehog_y*0.01, DEC );
          Serial1.print(" ");  
          
          Serial1.print("H=");
          Serial1.print(hedgehog_h*0.01, DEC );
          Serial1.print(" \n");  
      }
}

no output
marvelmind_beacons_comparison.pdf (195.9 KB)
i have the 4.9 version

Hi,
Where in the data does it show you the pinout of the unit, so you know where TX/Rx are?
What baud rate does it work at?

You can also bump up the Serial baud to the IDE to 115200, to give the controller more time to run code.

The data sheet sort of gave me an indication of what it is.
What does it actually do?
Light up, tell you its position using GPS, what?

Assume we know NOTHING about the product.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:
PS, I Googled and got this.

Description
The Super-Beacon is the most versatile, easy-to-use, and recommended beacon for Marvelmind precise indoor positioning and navigation system, particularly when starting with the Marvelmind Indoor “GPS” system. The system is used for autonomous robots, forklifts, drones, and people, as well as for industrial applications requiring precise positioning and localization indoors.

hi Tom,
i have uploaded the pin layout
the device is a system consisting of a modem that connect to pc and 5 beacons that you place in a large area and you can see the movement of the beacon that you set as a hedgehog on a software called dashboard. but the beacons coordinate can be transferred to arduino with UART.
i have tested the serial1 program that i told you about earlier like this

int hedgehog_x, hedgehog_y;// coordinates of hedgehog (X,Y), cm
int hedgehog_h;// height of hedgehog, cm
int hedgehog_pos_updated;// flag of new data from hedgehog received
#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;
void setup_hedgehog() 
{
  //Serial.begin(57600); // hedgehog transmits data on 500 kbps  
  Serial.begin(19200);
  hedgehog_serial_buf_ofs= 0;
  hedgehog_pos_updated= 0;
}
void loop_hedgehog()
{int incoming_byte;
 int total_received_in_loop;
 int packet_received;
//   Serial1.listen();

  total_received_in_loop= 0;
  packet_received= 0;
 // while(Serial.available() > 0)
  while (Serial1.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= Serial.read();
      incoming_byte= Serial1.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; 
        }
    }

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

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

void setup() {

  // initialize both serial ports:

  Serial.begin(19200);

  Serial1.begin(19200);
  setup_hedgehog();
}

void loop() {

  // read from port 1, send to port 0:

  if (Serial1.available()) {

    int inByte = altSerial.read();
String myString = String(inByte);
   // Serial.write(inByte);
  //  Serial.println(inByte);
    Serial.print("X=");
Serial.print(myString);
Serial.print("   ");  
       
Serial.print("Y=");
Serial.print(hedgehog_y);
Serial.print("   ");  

Serial.print("H=");
Serial.print(hedgehog_h);
Serial.print("   ");  

Serial.println();
  }

  // read from port 0, send to port 1:

  if (Serial1.available()) {

    int inByte = Serial.read();

    Serial1.write(inByte);


  }
}     

it is detecting the bytes coming from the beacon but not translating it


Hi,
How do you know it is in UART mode?

Also is the UART in TLL mode or RS232 comms mode.

If it can communicate with a PC on the UART, I would guess that it is RS232 levels and you will need a converter.
https://www.seeedstudio.com/blog/2019/12/11/rs232-vs-ttl-beginner-guide-to-serial-communication/#:~:text=RS232%20vs%20TTL%3A%20What's%20the%20difference%3F&text=RS232%20more%20extreme%20voltages%20help,noise%2C%20interference%2C%20and%20degradation.&text=The%20minimum%20and%20maximum%20voltages,0%20to%203.3V%2F5V.
Note that SPI mode and UART mode share a pin, so the device has to be setup to UART OR SPI.

Tom.. :smiley: :+1: :coffee: :australia:

from the software i choose usb+uart for the beacon that is transferring data to Arduino

Hi Tom
I figured out the source of the problem but I don't know how to solve it
the problem is that the packets coming from the device to the Arduino is too fast for the serial and if conditions to reach the right conclusions for the bytes order
i checked if the loops reach the row of code where the values are given to the xyz variables but the loops never reached it that is way i keep getting zeros
i disabled the conditions for the packets and used serial.print to see that of course i keep getting garbage reading that is only 1% of the time is right

this is the same code modified 
byte hedgehog_x, hedgehog_y;// coordinates of hedgehog (X,Y), cm
byte hedgehog_h;// height of hedgehog, cm
byte hedgehog_pos_updated;// flag of new data from hedgehog received
//#include <SoftwareSerial.h>
#include <AltSoftSerial.h>

AltSoftSerial altSerial(9, 8, 1);//rx tx
#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
    Serial1.begin(9600);
    //Serial1.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(Serial1.available() > 0)
    {
      //Serial.print(hedgehog_serial_buf_ofs);
      if (hedgehog_serial_buf_ofs>=HEDGEHOG_BUF_SIZE) break;// buffer overflow
      total_received_in_loop++;
      //Serial.println(hedgehog_serial_buf_ofs);
      if (total_received_in_loop>100) break;// too much data without required header
      {
      incoming_byte= Serial1.read();
      //Serial.println(incoming_byte);
      //Serial.println(total_received_in_loop);
      //delay(300);
      }
      /*if (hedgehog_serial_buf_ofs<5)
        {
          //Serial.println(hedgehog_serial_buf_ofs);
          if (incoming_byte != hedgehog_packet_header[hedgehog_serial_buf_ofs]) 
            {
              //hedgehog_serial_buf_ofs= 0;// restart bufer fill
              //Serial.println("continue");
              continue;
            }
        }  */   
      hedgehog_serial_buf[hedgehog_serial_buf_ofs++]= incoming_byte; 
      //Serial.println(hedgehog_serial_buf_ofs);
      if (hedgehog_serial_buf_ofs == HEDGEHOG_PACKET_SIZE)
        {// received packet with required header
          //Serial.println("message");
          packet_received= 1;
          hedgehog_serial_buf_ofs= 0;// restart bufer fill
          break; 
        }
   delay(10) ;}//end while
  if (packet_received)  
    {
      
      hedgehog_set_crc16(&hedgehog_serial_buf[0], HEDGEHOG_PACKET_SIZE);// calculate CRC checksum of packet
          hedgehog_x= (hedgehog_serial_buf[9]) + ((hedgehog_serial_buf[10])<<8);
          hedgehog_y= (hedgehog_serial_buf[11]) + ((hedgehog_serial_buf[12])<<8);// coordinates of hedgehog (X,Y), cm
          hedgehog_h= (hedgehog_serial_buf[13]) + ((hedgehog_serial_buf[14])<<8);// height of hedgehog, cm (FW V3.97+)
          hedgehog_pos_updated=1;// flag of new data from hedgehog received
      if ((hedgehog_serial_buf[HEDGEHOG_PACKET_SIZE] == 0)&&(hedgehog_serial_buf[HEDGEHOG_PACKET_SIZE+1] == 0))
        {// checksum success
          Serial.println("ok");
          hedgehog_x= (hedgehog_serial_buf[9]) + ((hedgehog_serial_buf[10])<<8);
          hedgehog_y= (hedgehog_serial_buf[11]) + ((hedgehog_serial_buf[12])<<8);// coordinates of hedgehog (X,Y), cm
          hedgehog_h= (hedgehog_serial_buf[13]) + ((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///
//SoftwareSerial mySerial(10, 11); //RX and TX
void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
  setup_hedgehog();//Marvelmind hedgehog support initialize
  //Serial.print(hedgehog_serial_buf_ofs);
  //altSerial(10, 9);
  //Serial1.begin(9600);
  //Serial1(19, 18, 1);//RX and TX and inverting logic
  //Serial2.begin(9600);
}

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

   if (hedgehog_pos_updated);
     {
          //hedgehog_pos_updated=0;

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

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.