Archive for the ‘Serial’ Category

Basic Processing to Arduino Communications

Friday, February 20th, 2009

Finally sat down and figured out how to send some basic signals via serial from Processing to an Arduino.  For this example I was just looking for basic functionality, so I settled for a simple way to turn a LED on and off.  It’s also mostly sample code gathered from the Internet.

The Processing code creates a small black square on the screen.  When the mouse cursor is moved over the square, it changes color to yellow and sends a “H” over serial to the Arduino.  While the Arduino detects a “H” on serial it will light the LED.

Here’s a video of it in action and describing how to get started.

Basic Processing to Arduino Communications from Morgellon on Vimeo.

  • Download Processing

http://processing.org/download/index.html

  • Download Arduino to Processing Library

http://www.arduino.cc/playground/Interfacing/Processing

Now that you’ve gotten all the files installed and in their proper places, try out my test code I used in the video.

Arduino Code (Download here)

//  Read data from the serial port and turn ON or OFF a light depending on the value

char val;         //Data received from the serial port
int ledPin = 13;  //Set value ledPin to pin 13

void setup(){
pinMode(ledPin, OUTPUT);  //Sets pin as OUTPUT
Serial.begin(9600);    //Start serial communication at 9600bps
}

void loop(){
if (Serial.available()){  //If data is available to read,
val = Serial.read();    //read it and store it as val
}
if (val == ‘H’){              //If H is recieved
digitalWrite(ledPin, HIGH);  //turn ON light
} else {
digitalWrite(ledPin, LOW);  //If not leave light OFF
}
delay(25);
}

Processing Code(Download here)

//Check if the mouse is over a rectangle and write the status to the serial port

import processing.serial.*;
import cc.arduino.*;


Serial port;    //Create object from Serial class

void setup() {
size(200, 200);
noStroke();
frameRate(10);
//Open the port that the board is connected to and use the same speed (9600bps)
port = new Serial(this, Serial.list()[0], 9600);
}

void draw() {
background (255);
if (mouseOverRect() == true) {  //If mouse if over square
fill(242, 204, 47);                    //change color
port.write(’H');              //send H to serial port
} else {            //If mouse is NOT over square
fill(0);          //change color
port.write(’L');  //send L to serial port
}
rect(50, 50, 100, 100);  //Draws the square
}

boolean mouseOverRect() {    //Tests if mouse is over square
return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150));
}

Arduino & Moblie Phone Communications

Thursday, January 8th, 2009

For several years, I have been a user of various smart-phones of different makes and models.  Once I used my first smart-phone, I was truly hooked by the “life style”. Soon, I was left with little desire to return to a “normal” phone that “just made calls”. I am always finding new applications that remind me a smart-phone is more like a small computer that is capable of making phone calls, than just a fancy phone.

When I entered the world of the *duinos, I remember the question “Can I hook up my Arduino to my phone?” entering somewhere in the back of my mind.  There it sat, in the deep recesses of the mind…. until recently.

Ideally, I would like the ability to plug in or sync an Arduino and run the Arduino IDE on a mobile phone.  I have little desire to replace my computer and keyboard for a phone as my main environment.  Although, I would like the ability to use the phone as a “field unit”. Perhaps using it to edit, tweak, or update versions of a sketch without the need of a PC or laptop.

I have no idea if this is at all possible… but in the course of searching the internet for answers I have found some interesting projects with *duino’s and mobile phones!

  • Here is an example of a BT Arduino communicating with a mobile phone over Blue-Tooth. http://www.youtube.com/watch?v=cgZiBl7Uzdo

This example is neat, but… the blue-tooth Arduino can be pricey and I’m really looking for a way to physical connect the arduino over USB… so we keep searching…

  • This example has serial output from an Arduino being displayed on an iPod Touch or iPhone. http://www.youtube.com/watch?v=mEM-VHZTqhk

This example caught my eye and interest! (Possibly due to the nature of owning an iPhone…) So, I decided to poke around and see if I could find more info on the process. Most of what I found was in Japanese or broken links.

http://d.hatena.ne.jp/tabletlet/20080328/ The site where the video originated and the Google translation http://translate.google.com/translate?hl=en&ie=UTF-8&u=http%3A%2F%2Fd.hatena.ne.jp%2Ftabletlet%2F20080328%2F&sl=ja&tl=en&history_state0=


http://novi.10.dtiblog.com/blog-entry-213.html Another site in Japanese with a bit more info on establishing the serial communications and the Google translation http://translate.google.com/translate?hl=en&ie=UTF-8&u=http%3A%2F%2Fnovi.10.dtiblog.com%2Fblog-entry-213.html&sl=ja&tl=en&history_state0=

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1207058161 A post in the Arduino.cc forums about connecting Arduino to iPod/iPhone serial.

http://devdot.wikispaces.com/Iphone+Serial+Port+Tutorial Info about iPod/iPhone serial communications.

http://pinouts.ru/Devices/ipod_pinout.shtml iPod/iPhone connector pin-out.

And of course, a few sources for iPod connectors and breakout boards:

Wireless Communication Part 1

Wednesday, November 12th, 2008

Today we are going to be playing with some 433 mhz radios from Parallax.

Transmitter $30

Receiever $40

Datasheet

Now this is only going to be one way communication, as these will either transmit or recieve but not both.  This pair is extremely easy to use, they say these will range over 500ft and will speak between 12,000 – 19.2 K baud.

To use these, you simply put them inline with the wired example, on the transmitter there is a ground, power, data and  power down.  Don’t worry about the power down, you know where to plug the other 3.  Data is going to be your tx pin.

On the reciever there are those 4 pins and a signal pin.  This signal pin shows how strong the signal is from the transmitter.  You can read this like any other analog value.  Your data pin goes to rx.

Transmitter

Transmitter

Reciever

Receiver

Transmitter Closeup

Transmitter Closeup

Receiver Closeup

Receiver Closeup

Wired Communication Between Arduinos

Saturday, November 8th, 2008

To do a wired serial conection you need 3 wires, rx, tx, ground.  Don’t forget the ground, that had me all confused and frustrated.  The tx (transmit) and rx (recieve) wires need to be crossed.

I wrote a simple sketch that starts at 0, outputs that value, increments by 1, outputs that value and so on.  This sketch will be used for all of my serial communication between Arduino posts. code

LCD output

LCD output

So I get my sketches running, one outputting that information and the second reading it and displaying it to an LCD.

Then I wire everything up.

This allows tx and rx between the 2 Arduino’s dont forget the common ground.  With wireless you do not have to have that common ground, my next 2 posts will be on such things.

Download the sketches I used

  • Cool Arduino Parts

  • You are currently browsing the archives for the Serial category.



  • Viagra online
  • Order cheap cialis
  • Buy viagra no prescription
  • Cialis online
  • Buy generic cialis
  • Order propecia no prescription
  • Cheap propecia online
  • Propecia online pharmacy
  • Order levitra online
  • Cheap price cialis
  • Online pharmacy levitra
  • Buy viagra online
  • Buy discount levitra
  • Cheap cialis online
  • Propecia hair loss