Show Posts
Pages: [1]
1  Using Arduino / Interfacing w/ Software on the Computer / Re: Problem with Ruby and serial port on: December 15, 2011, 02:59:24 am
I have now done some testing on my new Macbook Air and everything works great there.
So the serialport library for ruby on windows probably has some bug.
2  Using Arduino / Interfacing w/ Software on the Computer / Problem with Ruby and serial port on: December 14, 2011, 04:26:09 am
A have a problem when trying to read the serial port from my arduino. I am running on a Windows 7 64-bit with Ruby 1.9.2.
When i start my script nothing happens. To get it running i have to first start the Serial Monitor in Arduino IDE and see the data. Then close it and the ruby script works flawless.

I can now stop the script and start it again and it works, until i restart the computer or reset the arduino.
Right now i running it on a Teensy but it is the same on both Teensy and Arduino.

I have a Python script that does the same and it works without the work around.

Why it is doing this?

Ruby code:
require "serialport"
require "sequel"

def getTemperature(sp)
temp = ""
found_first_char = 0

#just read forever
while true do
sp_char = sp.getc 

if sp_char == "R" or found_first_char == 1
found_first_char = 1

if sp_char == "\n"

if sp_char 
temp = temp.concat(sp_char)

return temp

# connect to an in-memory database
DB = Sequel.sqlite('./templog.db')
# # create a dataset from the items table
temp_reads = DB[:temp_reads]
sp ="COM7", 115200, 8, 1, SerialPort::NONE)

while true do
temperature1 = getTemperature(sp)
temperature2 = getTemperature(sp)
time =
data = []
data = temperature1.split(' ')
a = data[0].split('=')[1]
t = data[1].split('=')[1]
temp_reads.insert(:timestamp => time, :temp => t.to_i, :address => a)
puts "Log timestamp: #{time}, temperature: #{t}, address: #{a}"
data = temperature2.split(' ')
a = data[0].split('=')[1]
t = data[1].split('=')[1]
temp_reads.insert(:timestamp => time, :temp => t.to_i, :address => a)
puts "Log timestamp: #{time}, temperature: #{t}, address: #{a}"

sleep 300


Arduino code:
#include <OneWire.h>

/* DS18S20 Temperature chip i/o */

OneWire  ds(10);  // on pin 10
const int redPin =  6;

void setup(void) {
  pinMode(redPin, OUTPUT);

void loop(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  if ( ! {
    //Serial.print("No more addresses.\n");
  for( i = 0; i < 8; i++) {
    Serial.print(addr[i], HEX);

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.print("CRC is not valid!\n");
  if ( addr[0] != 0x10) {
      Serial.print("Device is not a DS18S20 family device.\n");

  // The DallasTemperature library can do all this work for you!

  ds.write(0x44,1);         // start conversion, with parasite power on at the end
  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  present = ds.reset();;   
  ds.write(0xBE);         // Read Scratchpad

  //Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] =;
    //Serial.print(data[i], HEX);
    //Serial.print(" ");
  Serial.print(" T=");
  //Serial.print(" CRC=");
  //Serial.print( OneWire::crc8( data, 8), HEX);
  digitalWrite(redPin, HIGH);
  digitalWrite(redPin, LOW);

float getTemp(byte data[]) {
 int tr;
  //put in temp all the 8 bits of LSB (least significant byte)
  int LSB;
  int HSB;

  LSB = data[0];
  HSB = data[1];

  //check for negative temperature
  if (HSB > 0x80){
    LSB = !LSB + 1; //two's complement adjustment
    LSB = LSB * -1; //flip value negative.
  //COUNT PER Celsius degree (10h)
  int CPC = data[7];
  int CR = data[6];
  //drop bit 0
  tr = LSB >> 1;
  return (float)tr - (float)0.25 + (CPC - CR)/(float)CPC;
3  Forum 2005-2010 (read only) / Scandinavia / Re: Köpa WiShield on: March 21, 2010, 01:59:13 pm
Kanon, skall kolla på dessa.  smiley

Har tittat lite på BlackWidow från  asynclabs, den verkar rätt intressant i mitt fall.

WiFly, fungerar den på samma sätt som WiShield eller?
Om inte, finns det programkod för arduino till den?
4  Forum 2005-2010 (read only) / Scandinavia / Köpa WiShield on: March 21, 2010, 05:38:20 am

Jag håller på med ett litet projekt där jag har en Arduino Duemilanove som skall koppla upp sig mot en server och skicka lite data med jämna mellanrum. Jag vill att den skall koppla via Wifi så därför passar det ju bra med en WiShield.

Finns det något ställe i sverige som säljer sådana eller vad är bästa stället att beställa från?

Finns det någon annan liknande "shield" som är kompatibel med WiShield?

Pages: [1]