Send serial data via USB to Arduino Uno via pins 0 and 1

Okay, I apologise in advance. This is probably in the wrong place and all wrong in general. But I have no idea how to get going with this :confused:

I have an Arduino Uno. What I want to do is write a program on my computer in Python which, given some inputs, will send some data to the Uno via a USB cable connected at one end to my computer, and at the other to pins 0 and 1 on the Uno.

I want to use Python, as I'm getting the data from web APIs, processing it, and then I want the Uno to do stuff based on the output from the API.

I can (probably) sort the Python bit myself, as I have a lot of experience with it.

Please try not to laugh or shout as this is a bit crude, but I was thinking of just cutting open an old USB cable, and plugging the D+ and D- into pins 0 and 1, send some data as see what happens.

However, after having a look around, I found this post and am now confused if I need one of those things there?

This doesn't seem that tricky to do, but I'm struggling with it....

fukqoxuwi: I was thinking of just cutting open an old USB cable, and plugging the D+ and D- into pins 0 and 1, send some data as see what happens.

It is possible to do USB emulation in software with a few extra components but for your purposes that would be completely pointless since the Uno has a built in USB to TTL serial converter chip already connected to pins 0 and 1.

fukqoxuwi: and am now confused if I need one of those things there?

No, because the Uno has a built in one of those already connected to pins 0 and 1. You just plug a regular USB cable into the USB socket on the Uno and you're good to go. The USB-serial chip on the Uno creates a virtual COM port on your computer and you just need to send serial data from your Python program to that COM port. You're making things way more complicated than necessary.

fukqoxuwi:
now confused if I need one of those things there?

Probably not. I think you are just trying to re-invent the wheel. The USB connection shares the hardware serial with pins 0,1 so forget about the latter and concentrate on the former. If this is some real-time procedure, I guess this is just a matter of writing a programme that does what you want and sends the data to the COM port Arduino is connected to. If it is not real-time, you might simply accumulate the data in a file and use RealTerm to send it to Arduino.

Arduino doesn’t care where the data comes from, just so long as it can sensibly read it.

Many thanks so far for your responses. To quote my original post 'this doesn't seem that tricky', and it would appear it's not, I'm just trying to be too fancy.

Thanks for the link to that tutorial on serial data. Looks very handy for what I'm wanting to do.

Two quick side questions:

  • There are are some Arduinos, such as the Mini 05, which don't come with a big fat USB plug on them. If I was trying to work with one of them, would the cutting up the USB cable work?
  • How do you know that the board has a USB to TTL serial converter chip? Where do you go to find that information?

An option to pursue your original line of thought (if that be your intent) is for a USB/TTL convertor that will then allow you to connect with pins 0/1 or any other pair with soft UART emulation.

fukqoxuwi: How do you know that the board has a USB to TTL serial converter chip? Where do you go to find that information?[/li][/list]

I guess, if it doesn't have a USB socket, it probably doesn't have the converter chip either. A case in point is the Pro Mini, which uses an off-board adapter for programming. You can also programme it from a Uno with no adapter. Pro Mini is a stripped-down Uno. I guess the Mini 05 is something similar.

I don't think cutting up a USB cable will work with anything, and is a pointless exercise - particularly since you already have a Uno.

fukqoxuwi: I have an Arduino Uno. What I want to do is write a program on my computer in Python which, given some inputs, will send some data to the Uno via a USB cable connected at one end to my computer, and at the other to pins 0 and 1 on the Uno.

Have a look at this Python - Arduino demo

You need a USB-TTL cable if you are using an Arduino without a socket for a regular USB cable.

...R

Thanks again for everyone’s replies so far.

I’ve followed that guide on serial data and I’ve got something working. I’ve got three LEDs attached to pins 2 to 4. When I type <0> it flashes the first light connected to pin 2, <1> flashes pin 3, etc.

I can get it all working using the Arduino IDE fine, which I’m pretty please with actually. I thought I’d try and send some data from Terminal down that serial port using this command:

sudo echo '<0>' > /dev/cu.usbmodemFD511

(sudo as the file is owned by root and I can’t be bothered trying to fiddle with permissions) It’s coming back every time with:

-bash: /dev/cu.usbmodemFD511: Resource busy

I know this is an Arduino form, and I’m asking a question about OSX, but does anyone have any idea why this might be happening?

Two thoughts:

You can only have the port open in one program at a time. So if you already have it open in Serial Monitor you might get an error like that.

The Arduino Uno has circuitry that resets it whenever a serial connection is opened. This allows you to upload sketches without having to press the reset button at just the right time. It's possible that command resets the Uno and the Uno being in reset for that moment causes the error. You can disable the auto reset by putting a 10 uF capacitor between the Reset and GND pins.

"The Arduino Uno has circuitry that resets it whenever a serial connection is opened. "

Only if the terminal application is configure to use DTR. If DTR is turned off, terminal app can be opened/closed without a reset.