PDA

View Full Version : USB Interface




larswik
Sep 9, 2010, 02:05 AM
Hello, I just got my Sparksfun.com inventors kit which came with an Arduino USB interface board and a bread board for LED's resistors and more.

http://arduino.cc/en/Guide/MacOSX

It came with software and drivers that I installed. When I launch the software I need to select the serial port and all the code is done for you by just selecting a pulldown (Boring). When I picked the code I then select from another pulldown to upload to the board and the light blinked.

This is still above my skill level but I opened up xcode and pasted the code in and tried to run it in the console.

/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/

void setup() {
// initialize the digital pin as an output:
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}

When I tried to run this code I got errors which I was expecting, I just wanted to see what errors it kicked out. I am assuming it can be done from xcode but I lack the knowledge as to what code I am missing. I am guessing I need to import info for the serial port, info from the drivers that I installed and a way to send the information to the board

I would be greatfull for any incite to solve this. This is part of my over all goal in learning C / Objective C

Thanks!

-Lars



ScoobyMcDoo
Sep 9, 2010, 10:36 AM
First two things I see wrong there, is there is no main, and the API headers have not been included/imported.

jared_kipe
Sep 9, 2010, 10:54 AM
Arduino code cannot be compiled or run in Xcode.

Arduino code is similar to C in a lot of ways, but is not strict C, for example not having access to any of the C standard library.

There is no concept of "pins" in C.
delay() is called usleep() and is platform dependent.

C programs don't automatically provide a run loop, and name the most basic functions differently. main() vs setup()etc

larswik
Sep 9, 2010, 01:52 PM
jared_kipe...

I found this on the Adrinuo site this morning which was part of the FAQ. some one asked the question "Can I program the Arduino board in C?"

http://arduino.cc/en/Hacking/BuildProcess

It includes info like #include "WProgram.h" . Perhaps this class defines "pins" and it's methods?

Perhaps it is possible? I will read through it tonight when I have time.

Thanks again for your help!

chown33
Sep 9, 2010, 02:20 PM
Also google the obvious search terms:
arduino xcode

jared_kipe
Sep 9, 2010, 02:55 PM
jared_kipe...

I found this on the Adrinuo site this morning which was part of the FAQ. some one asked the question "Can I program the Arduino board in C?"

http://arduino.cc/en/Hacking/BuildProcess

It includes info like #include "WProgram.h" . Perhaps this class defines "pins" and it's methods?

Perhaps it is possible? I will read through it tonight when I have time.

Thanks again for your help!

And what would you expect an i386 or x86_64 cpu to do when you run that compiled code?

I'm not saying you couldn't use XCode as an editor, hell with some appropriate #define's you could easily use the code completion and just copy/paste your code back into the java arduino compiler.

BUT, I'm not sure what you expect to happen if you were to get a program to run on console.

If you want to learn C and then objective-C, the Learn C on the Mac book is amazing for that goal. And it certainly applies to programming on the Arduino, I've written some Arduino code myself recently and it is quite easy with my background in C and Obj-C.

larswik
Sep 9, 2010, 04:38 PM
Chown33 - hummm. that was one obvious step I over looked. When ever I have a programing question I always come here first. I will Google in the future.

jared_kipe - I stepped back from my Learning Object C 2.0 to the book you recommended last week. I have to say I love that book too.

To give you an idea of what I am trying to do in the next couple years and why I am learning all this. My goal is to write an app for the iPad that will have a graphical interface. Using curves (like animating a 3D camera) is to send information from the ipad's bluetooth to a microcontroller that will drive a stepper motor. My friend designs proprietary circuit boards for printers and is helping with the hardware side. I need to learn the software side. I bought the Adrinuo kit to get a feel for how the software interacts with hardware.

I really am thankful for the help you guys provide!

-Lars

chown33
Sep 9, 2010, 05:25 PM
... My goal is to write an app for the iPad that will have a graphical interface. Using curves (like animating a 3D camera) is to send information from the ipad's bluetooth to a microcontroller that will drive a stepper motor.

The bluetooth support in iOS is constrained. AFAIK, it's not possible to communicate with arbitrary devices:
http://developer.apple.com/library/ios/#qa/qa2009/qa1657.html

This may have changed recently, since Apple made other changes to the iOS Developer Program today. Or it may change at a later date. However, AFAIK, developing arbitrary accessories is not currently included in the $99/yr program.

This doesn't mean all is lost. If the Bluetooth accessory pretends to be headphones or speakers, you can synthesize an audio signal and "play" it to the "speakers", which the device then decodes and interprets as commands. You can similarly read and decode an audio signal from a Bluetooth "microphone". For example, a Bell-103 compatible 300 bps FSK signal might be practical. Or DTMF message-strings. Or biphase, or various other encodings.

I have no idea whether this is intended as a commercial concept or a small-scale or hobbyist thing. Maybe by the time you are able to make this all work, the technology or the licensing will have changed in ways no one can predict. There could be $5 wireless chips the size of miniSD cards, and all you have to do is connect to an ad hoc wireless network using UDP.

Still, it never hurts to understand hardware. Just don't get too attached to doing things in one particular way, especially if the plan is commercial.

jared_kipe
Sep 9, 2010, 07:23 PM
Ironically enough I made a super simple iPhone app that uses two IR diodes to send Sony protocol IR signals to my Arduino. And obviously programmed the Arduino to gather and respond to these signals.

chown33
Sep 9, 2010, 07:59 PM
Ironically enough I made a super simple iPhone app that uses two IR diodes to send Sony protocol IR signals to my Arduino. And obviously programmed the Arduino to gather and respond to these signals.

Are you driving the IR LEDs using the iPhone's headphone audio outputs? Or did you hack some Bluetooth headphones?

larswik
Sep 9, 2010, 09:07 PM
Chown33 - I know there are limitations with the bluetooth. The first app that I create was going to work on a mac laptop using the built-in bluetooth. In a couple years I expect the market to be flooded with tablets and if Apple has the still high-all-mighty attitude and controls the way you can use their gear, well then, hello Android platform! Or I suppose I can Jail Break the iPad and use it the way I want to.

This is a Hobby but for the last couple years I kept saying "If only I could do this". So I quit complaining and am working towards my goal!

Thanks for the insight and the obvious Check Google fo the answers first :)

-Lars

jared_kipe
Sep 10, 2010, 11:39 AM
Are you driving the IR LEDs using the iPhone's headphone audio outputs? Or did you hack some Bluetooth headphones?

Headphone out.

chown33
Sep 10, 2010, 12:29 PM
Headphone out.

Can you post a link to circuit schematics?

jared_kipe
Sep 10, 2010, 01:10 PM
Sure

headphoneLeft --------------_----|
^ |
| V
headphoneRight ---------------|-----


Just hook two IR diodes in opposing directions between the left and right channels. You don't need to do anything with ground.
Initially I had a low resistance resistor in series as well, like 22Ohm, but I took it out and it works fine (I figured "MOWR POWER, if it blows up the Genius bar will replace it")

chown33
Sep 10, 2010, 01:23 PM
Sure

headphoneLeft --------------_----|
^ |
| V
headphoneRight ---------------|-----


Just hook two IR diodes in opposing directions between the left and right channels. You don't need to do anything with ground.
Initially I had a low resistance resistor in series as well, like 22Ohm, but I took it out and it works fine (I figured "MOWR POWER, if it blows up the Genius bar will replace it")
When you said 2 diodes, I thought you might have done it that way. The max output power from the headphone amp is probably low enough it's hard to burn out. And I wouldn't be surprised if the amp had builtin overdrive protection.

How do you synthesize the 40 KHz carrier? Are you relying on 20 Khz half-wave rectification by the paired IR diodes to achieve frequency doubling?

jared_kipe
Sep 10, 2010, 01:48 PM
When you said 2 diodes, I thought you might have done it that way. The max output power from the headphone amp is probably low enough it's hard to burn out. And I wouldn't be surprised if the amp had builtin overdrive protection.

How do you synthesize the 40 KHz carrier? Are you relying on 20 Khz half-wave rectification by the paired IR diodes to achieve frequency doubling?
Originally I was using a 3V coin battery and transistor to trigger it off one channel, but this seemed easier in the long run (it was).

Yes, I used audacity to create a 19 KHz full sine wave, edited for the specific time coding 2.4ms start, 1.2ms One, and .6ms zero
Copied it to another channel and inverted it.

I had more problems getting the iphone to actually play the audio, because of format and timing issues. Attached is a single command with quite a bit of silence in the beginning (otherwise the ipod will not play a 20ms file)

This playing in the ipod was the first instance I had of reliable communication with my Arduino over IR. Obviously I have made an app that can send arbitrary codes as well now.

chown33
Sep 10, 2010, 06:59 PM
Thanks for the info, jared_kipe. I'm always interested to see little hacks hooked up to little computers.

stopshinal
Oct 31, 2010, 08:56 AM
I'm just now getting acquainted with this thread.

While I know this might be a bit much to ask, I was curious if someone may be able to direct me, or assist me, with creating an app which can communicate to, and from, an arduino via the head phone output. Doesn't need to be IR, in fact, I would prefer it not to be.

J

jared_kipe
Oct 31, 2010, 09:35 AM
First of all, what are you communicating, and why does it need to be an iPhone?

In a way, IR is ideal because it is easy to modulate a signal as pulses that the arduino can measure. Getting it back to the iPhone would not be so easy.

chown33
Oct 31, 2010, 12:09 PM
While I know this might be a bit much to ask, I was curious if someone may be able to direct me, or assist me, with creating an app which can communicate to, and from, an arduino via the head phone output. Doesn't need to be IR, in fact, I would prefer it not to be.


What distance does it need to communicate over?

Does it need to be wireless (IR is wireless), or can it be wired (USB is wired)?

stopshinal
Oct 31, 2010, 04:49 PM
I'm trying to control a few hack job gadgets in my car - one of which is a squirt gun on a turret hiding behind the emblem on my trunk.

Communication needs to go both ways, because I am also attempting to read OBDII ports for iTouch apps to visually display.

Why apple products? Well, for a noob such as myself, I see this as a brillant project which will require all sorts of learning. Simple push buttons and an LCD would work - but I feel other projects could benefit from this sort of project development. I'm sure other people can come up with far more important applications for arduino/iTouch integration.

What distance does it need to communicate over?

Does it need to be wireless (IR is wireless), or can it be wired (USB is wired)?

I prefer wired, as I could also use the connection to charge the device.

chown33
Nov 1, 2010, 11:30 AM
Well now you're right back to your original question in another thread:
Interface iPhone/iTouch via 30pin to microcontroller
http://forums.macrumors.com/showthread.php?t=1040106

The answer there was "There is no available, low cost, solution for home brew hardware projects." That hasn't changed, when the connection involves the 30-pin connector. You'll have to look for hacks using a web search engine, and implement them at your own risk.

Now you have to decide what kind of hack you're going to use: one involving the 30-pin connector or one involving the audio outputs (or inputs). Either way, you'll have to do some searching, and you may have to improve your programming skills before making a choice. When I first pointed you to this thread it was only to show there are output mechanisms that don't involve the 30-pin connector or WiFi. It wasn't to point you to a complete ready-to-use solution.

As for OBDII, google search terms: obdii iphone
There's an app for that, and it requires an OBDII to WiFi adapter. Using WiFi was also one of the replies to your other thread. That hasn't changed either.