Hello!
I have pretty basic configuration with Arduino Uno + LED Screen, connected to Mac (MacOS v 10.9.1), arduino IDE v 1.0.5.
Arduino client receives character data by serial port and put this data to LED screen
#include <LiquidCrystal.h>
LiquidCrystal lcd(4, 5, 10, 11, 12, 13);
const int numRows = 2;
const int numCols = 16;
int col = 0;
int row = 0;
char ch;
void setup() {
lcd.begin(numCols, numRows);
lcd.clear();
Serial.begin(9600);
}
void loop() {
lcd.setCursor(col, row);
if (Serial.available()) {
ch = Serial.read();
if(!isSpecialCharacter(ch)) {
lcd.write(ch);
calcColRow();
lcd.setCursor(col, 0);
}
}
delay(500);
}
// check if character is special
boolean isSpecialCharacter(char ch) {
return (ch==0x0a)||(ch==0x0d);
}
// where to move cursor
void calcColRow() {
col++;
if (col>15) {
if ((row==0)) {
col = 0;
row = 1;
} else {
col = 0;
row = 0;
lcd.clear();
}
}
}
also I have ruby/sinatra code, which puts data to serial port directly:
require 'rubygems'
require 'sinatra'
require 'haml'
require 'serialport'
require 'logger'
require 'selenium-webdriver'
set :haml, { format: :html5, attr_wrapper: '"'}
get '/' do
haml :index
end
get '/value' do
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://localhost:4567/"
element = driver.find_element(:id, "list")
jam_value = element.text
write_to_sp(jam_value)
end
def write_to_sp(value)
logger = Logger.new(STDOUT)
logger.level = Logger::DEBUG
port_str = "/dev/tty.usbmodem1411"
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
logger.debug(sp)
sp.write(value + " ")
logger.debug(value)
sp.close
end
The problem is I can only see result if Arduino IDE is running and serial console is open. Otherwise I couldn't see even leds on Arduino board blinking while receiving data. Could please somebody who faced such troubles already help me?
THnks!