Pages: [1]   Go Down
Author Topic: Arduino and Carbon  (Read 999 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Greetings.

I'm coding a Macintosh carbon app to communicate with my Arduino. I'm wondering if anybody can give me some direction on how to get my application to recognize my Arduino, which is connected via USB (serial).

I've found a tutorial on the Apple Developer website demonstrating how to communicate with USB devices, but it requires a product and vendor ID. Do these exist for the Arduino?

Thanks for any advice,

Jeremy
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The USB drivers for Arduino (actually for the FTDI chip on the board) make the board show up as a virtual com port.  So you should be looking for documentation on dealing with serial ports or com ports.  Hope that helps.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Maker of BlinkM and blink(1), ScrewShield, Wiichuck adpater, and many other Arduino thingies
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Jeremy,
The Arduino doesn't appear as a USB device really.  The USB-to-serial chip on the Arduino and the driver software you installed for it make Arduino look like a serial port. If you were writing straight C code (which I assume you are since Carbon is a set of C APIs), then you would just use the normal C open() file function on the path to the serial port (e.g. something like "/dev/tty.usbserial") and then the standard read(), write(), and close() functions on the file descriptor returned by open().  If you're unfamiliar with those C functions, just about any C reference guide will help.  Speaking to serial ports is a little more complex than reading/writing files, but not much.  Do a search on the net for C code that talks to modems, serial terminals, GPS receivers, or other things that use serial ports.  You'll find lots of code.

If after all hunting around and it still doesn't make sense, let me know and I can post some simple command-line C examples that talk to Arduino.

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey. Thanks for your answer.

I thought that it was more complicated than just reading and writing to files. Really figured that it was more complex (establishing a baud rate for connection speed, determining read and write events). I'll look into it this afternoon. I was also looking at Apple Developer documentation on reading a list of Serial devices, which only showed the modem and bluetooth (even though /dev/tty.usbserial was showing up in the Terminal). Anyway, I'd love to see an example or two.

Jeremy
Logged

Orlando, FL
Offline Offline
Full Member
***
Karma: 0
Posts: 147
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a few xCode expamples for talking to the Arduino using Cocoa and C++.  These examples should help you a bit.   http:// http://web.mac.com/miked13/iWeb/Arduino

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Maker of BlinkM and blink(1), ScrewShield, Wiichuck adpater, and many other Arduino thingies
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

stealthtransam, that's a great example.

For another take, using vanilla POSIX C (so should work on Linux and Windows-with-Cygwin), check out:
http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/
Logged

Orlando, FL
Offline Offline
Full Member
***
Karma: 0
Posts: 147
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

same principal as my examples.  I just dumbed mine down for teaching reasons.  Teach them the basics then short cut the code.
Logged

Brisbane, QLD, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have tried all the c examples I can find and I cannot get open() to work.  It always returns with an error 'no such file or directory exists' even though I'm copying exactly the file path as listed when I do the following under Mac OsX Tiger console:

ls /dev/tty.*

I get back a few adresses but this is the one that s the arduino and open fails to see:

/dev/tty.usbserial-A10?16fZ

What am I doing wrong here?  screen works, I can see the data coming in... but this damn open() just tells me my file doesnt exist?
Logged

Brisbane, QLD, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I semi solved my problem, got it to work now.  from advice in this thread:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1161192417

I used Sudo to create an alias to my arduino.

sudo ln -s /dev/tty.usbserial-* /dev/tty.arduino

and then my c code successfully opened the /dev/tty.arduino

it makes me think that my serialized arduino's name is problematic.  There is afterall a ? in the sring
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For some reason the drivers from FTDI (which makes the USB-serial chip on the Arduino) assign names with non-ASCII characters to their devices.  Don't ask me why.
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
or some reason the drivers from FTDI (which makes the USB-serial chip on the Arduino) assign names with non-ASCII characters to their devices.  Don't ask me why.

Because if the FTDI device has a serial number assigned the driver will use that serial number in the device special file name.  I am particularly grateful for this feature, as I don't have to worry about when and where a device gets enumerated when using multiple devices.  If the device does not have a serial number the device special file gets a sequential name bsaed on when/where it was found (all other Mac rs232/usb drivers I've used operate this way exclusively, e.g. Keyspan).

I suspect there is a non-printable character in the serial number.  ls /dev/tty.usb* | od -c may give you a clue as to wether or not I'm correct.

FTDI provides some tools that allow you to assign/reassign the serial number; unfortunately they are windows-only.

-j
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I know that, and I understand why you'd want each chip to have a serial number.  It seems pretty silly to put non-printing characters in your serial number - or if you really need a binary serial number, at least convert it to text when you map the serial number to a device filename.  
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Agreed, binary characters in device special file names make no sense.

Does the FT232 come serialized?  I know I've got a couple of rs232/usb adapters that do not (er, make that did not  smiley ) have serial numbers assigned.

Not sure if assigning a serial number is part of the Arduino manufacturing process, but technically (not sure about practically) it wouldn't be difficult to assign serial numbers, and even encode info about wheich release of arduino it was in the serial number.  Don't suppose it would help windows folks, but Mac users would see it in the port name and linux users could find it with some system tools, and the arduino install process could even add some udev rules to make it show up in the device special file name for the linux folks.

-j
Logged

Pages: [1]   Go Up
Jump to: