Receving multiple byte binary numers over serial?

initial value of counter should probably be zero not nine

wg0z:
initial value of counter should probably be zero not nine

WAHOO! That WORKED! Except I was only getting 2 bytes for pressure at the receive end - had to declare my 'sensor2' byte as long - now it is all working!!! :slight_smile:

Thank you VERY much guys! I owe you a coffee (or something stronger)!

Revised Tx code (for anyone that wants it)! Reads 3 sensor values (16 bit, 32 bit, and 16 bit) and transmits them over serial for computations at the receive end.

/*
  Software Transmit test
 */

#include <SoftwareSerial.h>
// software serial #1: RX = digital pin 10 (not used), TX = digital pin 18
SoftwareSerial portOne(10, 18);

int sensor1 = 0x1c3d ; // Compass, 16 bit
long sensor2 = 0x456c186c ; // Pressure, 32 bits
int sensor3 = 0x3a5f ; // Depth, 16 bit

struct DOFDATA
{
  uint16_t compass;
  uint32_t pressure;
  uint16_t depth;
};


void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  // Start software serial port
  portOne.begin(300);

}

void loop() {
  // data to send
  DOFDATA dd;
  dd.compass = sensor1 ;
  dd.pressure = sensor2 ;
  dd.depth = sensor3 ;


  int numBytes = portOne.write((byte*)&dd, sizeof(dd));
  Serial.println ("Sent") ;
  
  delay (10000) ;

    
  }

DianneB:
When I print the value of counter, it is stuck at 9.

My bad; that was for my debugging; did not have a software serial available for testing.

wg0z:
initial value of counter should probably be zero not nine

Good catch :wink: