Tuesday, November 12, 2013

Prepare Arduino to send data to Raspberry Pi via USB

It's a example to send data from Arduino to Raspberry Pi via USB. In this post, I will show a simple program in Arduino side (tested on Arduino Due), to send something out to USB, and also toggle the on-board LED. In the next post, I will show how to receive in Raspberry Pi Board, from USB, using Python.

The code in Arduino Due to send "Hello Pi" to USB and toggle LED repeatly every second.

int pinLED = 13;
boolean ledon;

void setup() {
  pinMode(pinLED, OUTPUT);
  ledon = true;
void loop() {
  Serial.print("Hello Pi\n");
  digitalWrite(pinLED, ledon = !ledon);

The code simple send "Hello Pi" to Serial port (USB) repeatly. After download to your Arduino board, you can use the build-in Tools > Serial Monitor to varify it.

No comments: