Pages: [1]   Go Down
Author Topic: Best Interfacing program  (Read 519 times)
0 Members and 1 Guest are viewing this topic.
Indiana, US
Offline Offline
Newbie
*
Karma: 0
Posts: 39
*_+
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are quite a few options when it comes to software that can interface with arduino via serial, and none of them look very simple (or at least not to me) I was just looking for some recommendations for the simplest method/language to use with an Arduino diecimila and Windows XP or Slackware 12 p

I am comfortable with C++ but I have never interfaced with serial before before

I couldn't get serial working in python but I am also unfamiliar to its syntax

any pointers/tutorials/links are greatly appreciated
Logged

Austin, TX USA
Offline Offline
God Member
*****
Karma: 4
Posts: 997
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey, action_owl,

If C# isn't too far removed from C++ for you, serial communication is pretty easy in Windows:

Quote
using System.IO.Ports;
SerialPort port = new SerialPort(port_name, 9600, Parity.None, 8, StopBits.One);
port.Open();
port.Write("G"); // write a character
while (true)
  if (port.BytesToRead > 0)
  { // read characters
    char c = (char)port.ReadChar();
    // use c
    ...
  }

You can get a list of the installed ports with

string[] ports = SerialPort.GetPortNames();

If C# is out of the question, it's only a little more complicated to configure a serial port in Windows in C++.  Once it's set up, it's not that tricky: http://www.ontrak.net/mfc.htm.

« Last Edit: October 06, 2008, 04:12:52 pm by mikalhart » Logged

Grenoble/Lyon - France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 363
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you understood how to write code in the Arduino IDE, you should try it's older brother, Processing. This is a language with a very smooth learning curve, but it's real powerful.

http://www.processing.org
Logged


Indiana, US
Offline Offline
Newbie
*
Karma: 0
Posts: 39
*_+
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow, that was the fastest response that I have ever had in a forum!

I already downloaded Processing and firmata in an attempt to figure out the serial communication, so I think I'll give that another go around, the Arduino IDE was really easy to work with

the arduinio uses WIRING to program to the ardunio right?
it flows so easy I have no idea as to what language I've been using

If Processing is a brick wall for me then I'll give C# a hug and try it out

thanks for the help I'll be sure to repost with my results
Logged

Austin, TX USA
Offline Offline
God Member
*****
Karma: 4
Posts: 997
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

action_owl, since you are into C++ (so am I), it's worth mentioning that WIRING on the Arduino is really pure C++ (with some VERY small tweaks)!  We have been having a debate on another thread about whether that fact is clear or not, so your comment caught my eye.

Mikal
« Last Edit: October 06, 2008, 07:54:16 pm by mikalhart » Logged

Indiana, US
Offline Offline
Newbie
*
Karma: 0
Posts: 39
*_+
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

mikalhart,
yeah i totally agree that WIRING is very very similar to C++ but I definitely like that about the language and I noticed PROCESSING is similar as well.
BTW I was able to get communication to my arduino to my computer via PROCESSING (finally) I don't know why I was making it so hard.
I just used the serial read example in processing and I made my own code for the arduino because their code didn't work out for me I also added 1 line to the processing sketch and made my own WIRING sketch here's the code for anyone else having difficulties it's what worked for me:

PROCESSING SKETCH:
import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

void setup()
{
  size(200, 200);
  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw()
{

  val=0; //this is all i changed so that it would blink on and off
  
if ( myPort.available() > 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  }
  background(255);             // Set background to white
  if (val == 0) {              // If the serial value is 0,
    fill(0);                   // set fill to black
  }
  else {                       // If the serial value is not 0,
    fill(204);                 // set fill to light gray
  }
  rect(50, 50, 100, 100);
}



ARDUINO SKETCH (WIRING):



int ledpin = 9; //led on pin 9 to show that the arduino is sending a 1 or a 0

void setup() {            
  Serial.begin(9600);
pinMode(ledpin,OUTPUT);
}

void loop() {
digitalWrite(ledpin, HIGH);
Serial.println(0, DEC);
delay(100);        
digitalWrite(ledpin,LOW);  
Serial.println(1,DEC);
delay(100);
}
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good to hear you have it sorted, thanks for sharing your code.

You didn't mention it, but you may have noticed that Processing is actually Java. That fact is not emphasized on the Processing site for the same reason C++ isn't on the Arduino site; the desire to encourage new users to grab code and tinker without concern for a daunting programming language under the covers.
Logged

Pages: [1]   Go Up
Jump to: