Skip to main content
3 of 4
added 1070 characters in body

Unexpected output form Serial.println

So I have a teensy and an arduino uno connected together via I2C, however some very odd behavior is occurring, when monitoring the serial connection for shorter data sent over I2C I receive the expected serial output. However if the data is longer I only receive 2 characters. More strange even is that if I send the longer data again I receive none, but if I send the shorter data I receive the expected output. After sending the shorter data again sending the longer data will result is the odd 2 characters.

Uno code //#include <DmxSimple.h>

#include <Wire.h>

boolean pinout = 0;
byte current[512];

void setup() {
  // put your setup code here, to run once:
  Wire.begin(1);
  Serial.begin(115200);
  Wire.onReceive(data);
  //DmxSimple.usePin(3);
  //DmxSimple.maxChannel(30);
}

void loop() {
  
}

void data(int numBytes){
//Serial.println("DATA RECIVED");

 delay(500);

 char input[20];
 int pos = 0;

 while(Wire.available()){
   input[pos++] = Wire.read();
  }
  input[pos++] = '\0';

  Serial.print("Recived \"");
  Serial.print(input);
  Serial.println("\"");

  char* next = strchr(input, ',');
  while(next != 0){  
  *next = 0;
  next++;
  char* splitter = strchr(next, ':');
  if(splitter != 0){
  *splitter = 0;
  splitter++;
  int channel = atoi(next);
  int value = atoi(splitter);
      //DmxSimple.write(channel,value);
      Serial.print(channel); Serial.print(":"); Serial.println(value);
    }
  } 
}

Teensy code - https://gist.github.com/hddfilestorage/47c464e282bb1844c954 (If modifying the teensy code to run on a second arduino replace the line #include <i2c_t3.h> with #include <Wire.h> no other changes should be necessary)

To use the Teensy code open a serial terminal to access it, press 't' to send a long packet, or any other character to send a shorter one.