Arduino Notes

View

Posted by Rico's Nerd Cluster on March 6, 2019

Common Commands

  • millis() is unsigned long
1
unsigned long previous_time = millis()
  • uint8_t lowByte(uint16_t value);
1
2
3
uint16_t value = 0x1234;

uint8_t lower = lowByte(value);
  • serial_port.println() vs serial_port.write()
    • serial_port.println() adds carriage \r, and \n
      • it knows the size of the string because a C-string actually ends with a special null terminator (\0). We must add the null ourselves
  • what’s the difference between unsigned char and signed char? Any difference in serial comm?
    • signed char: -128 to 127, signed char 0 - 255
    • So from a serial communication’s perspective, there’s no practical difference. However, to interpret data, yes, and unsigned char makes more sense for ASCII data

Serial Interface

  • There might be a permission issue about serial port. Just do:
1
sudo chmod a+rw /dev/ttyUSB0
  • Also, in Arduino, the timing for decoding might be messed up for serial. Hit the start button for serial to work properl

  • numBytesWaiting = SERIAL_GAS_DETECT.available(); is the hardware serial interface. returns number of available bytes in the serial receive buffer.

  • Teensy sketch uploads could corrupt Serial… One Can do a file checksum on the host linux machine, using md5sum

  • “lockable teensy” is to clone hex dump. (defined in PRJC)