arduino-sketch.ino 655 B

1234567891011121314151617
  1. void setup() {
  2. // $ stty -F /dev/ttyUSB0 | grep speed
  3. Serial.begin(115200);
  4. }
  5. void loop() {
  6. // effective sample rate measured with "Probe Rate" block
  7. delayMicroseconds(800);
  8. // > On ATmega based boards [...], it takes about 100 microseconds
  9. // > (0.0001 s) > to read an analog input, [...]
  10. // https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/
  11. unsigned short reading = analogRead(A0);
  12. // $ tail --follow /dev/ttyUSB0 | od --format=u2 --endian=big --width=2
  13. // 16 bits/sample / 115200 Baud * 1e6 μs/sec = 139 μs/sample
  14. Serial.write(reading >> 8);
  15. Serial.write(reading & 0xff);
  16. }