Skip to content

Instantly share code, notes, and snippets.

@nefo-mi
Created August 15, 2012 16:04
Show Gist options
  • Save nefo-mi/3361233 to your computer and use it in GitHub Desktop.
Save nefo-mi/3361233 to your computer and use it in GitHub Desktop.
Arduino Serial
#include <LiquidCrystal.h>
int incomingByte;
char inByte;
String inMsg;
LiquidCrystal lcd(7,8,9,10,11,12,13);
void setup()
{
lcd.begin(2, 16);
lcd.clear();
lcd.print("*Hello World*");
lcd.setCursor(1, 1);
lcd.print("homuhomu");
Serial.begin(9600);
Serial.println("setupDone");
}
void loop()
{
if (Serial.available() > 0) {
inByte = Serial.read();
if((inByte >= 65 && inByte <= 90) || (inByte >= 97 && inByte <= 122)
|| (inByte >= 48 && inByte <= 57) || (inByte == 43)
|| (inByte == 61) || (inByte == 63)){
inMsg.concat(inByte);
}
}
if (inByte == 10 || inByte == 13){
inByte = 0;
lcd.clear();
lcd.print(inMsg);
inMsg = "";
}
}
[1] pry(main)> require 'serialport'
=> true
[2] pry(main)> sp = SerialPort.new("/dev/ttyACM0", 9600, 8, 1, SerialPort::NONE)
=> #<SerialPort:fd 5>
[3] pry(main)> sp.puts "homuhomu"
=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment