Newbie serial and power questions

Hello to the forum. Even though I am new to Arduino, I have a lifetime of experience in electronics (designed TTL, CMOS, 8080, Z80, PIC, etc. hardware) and programming (assembler, C, C++, C#.Net, etc.)

I have a Uno R3 and an Ethernet shield, and have successfully built and run the example LED flasher and the example Ethernet DHCP and static IP connectivity sketches. Everything works as expected.

I want to build a shield, probably with a PIC, that sits above the Ethernet shield, and connects to the outside world. This shield will send on/off data from several switches to an Ethernet client. This should be no problem. It also will control up to six servos using the Uno's PWM pins. Again, no problem.

The shield needs to send to the Ethernet client 8 bits of data its PIC receives over a serial pin. It would be convenient to send this to the Uno via a serial connection.

Question 1: Can I use pins 0 and 1 for the PIC on my shield to communicate with the Uno at TTL levels if I don't plug anything into the USB jack? The Ethernet shield doesn't use them, and the Uno schematic indicates this should be possible, but I'm not sure.

I'm confused about how the Uno's USB port and pins 0 and 1 are related. In a sketch, Serial.xxx() initializes and communicates via the USB port. Does the Serial class also manipulate pins 0 and 1 simultaneously? If so, that's great. I will never have anything plugged into the USB connector while this device is running, so can I then use pins 0 and 1 for a serial connection to my sketch? If the Serial class doesn't manipulate pins 0 and 1, what should I use instead?

Question 2: I want to plug a 9VDC power supply into my shield, which will provide regulated 5V to its PIC and other circuits, and a separate 5V to the servos. I want to feed this 9V to the Uno on the Power.Vin pin. The Uno will then provide 5V to its internal chips, and to the Ethernet shield.

Is this how it works? I want one 9V power connection to the whole stack, and I'd rather not feed 5V from my shield to the Ethernet Shield and the Uno.

Thanks in advance for definitive answers to my questions. I'm impressed with Arduino, and think it will make my life much easier.

--- Mike

1 Sounds reasonable. Serial class manages rx/tx

2 How about connecting a 5 volt supply directly to the 5 volt pin on the Arduino.

.

LarryD:

1 Sounds reasonable. Serial class manages rx/tx

2 How about connecting a 5 volt supply directly to the 5 volt pin on the Arduino.

.

Yes, I could do that, but then the 5V regulator on my shield will dissipate more power. Why not let the Uno's regulator share the load?

LarryD:

1 Sounds reasonable. Serial class manages rx/tx

.

Sorry.... I missed this important quote in my previous response. I'm pleased that #1 sounds reasonable. I'll just leave the USB unplugged while using my shield. Should I plan to put two jumpers on my shield to connect/disconnect the PIC from pins 0 and 1 while using the Uno's USB port to upload the sketch, and connect them only when I'm ready to run the stack stand-alone?

Thanks again.

--- Mike

I have done similar, i.e. incorporated jumpers to disconnect rx/tx.
Maybe use 1K series resistors similar to what Rev 3 has.

.

What is the pic for?, I can't see any need for it! The Arduino is more than capable of handllng every thing you want on it's own.

Mark

holmes4: What is the pic for?, I can't see any need for it! The Arduino is more than capable of handllng every thing you want on it's own.

Mark

You might be right; I need to study my requirements closer. This project is for a model railroad. A C#.Net program runs in the dispatcher's office. He can monitor train locations and set semaphore signals. I want to use one Uno and shields to control signals and monitor occupancy for three railroad stations.

Each of those stations has two semaphores, so the six Uno PWM pins are sufficient for those six servos. But the device will have much more capability.

Each locomotive will be equipped with a 6-pin PIC that flashes an infrared LED with an 8-bit ID code. An IR photodiode between the rails detects the flashes as the loco passes over it. The stack must capture the loco's ID and send it to the dispatcher. It needs to synchronize and capture the pulses from the IR detector. Perhaps the Uno could do this on a digital pin. That's three pins.

Each station also needs a pushbutton input -- another three pins. Finally, I need a way to configure each station's servo movement on a one-time basis, and store the maximum movement in EEPROM. My original design uses a DIP switch, but maybe I can move that function to software, and issue commands over Ethernet.

It all deserves more thinking and testing to see what the Uno can do. Initially I thought there might not be enough digital pins for one Uno to handle three stations, but perhaps that's not the case if I use software to replace some hardware.

My next step is to write a simple Ethernet Server to see if my dispatcher's panel can connect. Previously I used a Technologic board running Linux and a TCP socket server I wrote. The dispatcher's panel connected on port 9000, and everything was golden. I'm thinking the Arduino Ethernet Server will connect just fine. Fortunately, the dispatcher's program has the ability to send ASCII to the server and display what comes back, so Arduino's example Ethernet Server should work with just a couple of tweaks.

---Mike

Question 1: Can I use pins 0 and 1 for the PIC on my shield to communicate with the Uno at TTL levels if I don't plug anything into the USB jack?

You should be able to. If you put an isolation diode between the pic tx and arduino rx, you can probably use both the arduino usb serial interface and the pic serial interface.

zoomkat, yes this works, used Schottky diodes here.

LarryD: zoomkat, yes this works, used Schottky diodes here.

I just use the usual small .7v drop signal diodes. Pulling the rx pin down to .7v is enough in my test for the rx pin to be detected as being low.

MikeDodd: I'm confused about how the Uno's USB port and pins 0 and 1 are related. In a sketch, Serial.xxx() initializes and communicates via the USB port.

The Atmega328 includes a hardware USART and its pins are brought out as Pins 0 and 1 on the Uno board.

Then there is another device (forget its ref number) that converts between serial and USB - it connects to the same Atmega328 pins.

By contrast, the Atmega32U4 used in the Leonardo (and others) generates the USB signals internally and the communication with the PC is not brought out on any pins on the Leonardo board.

On the Uno (and Mega) you can use Serial to communicate with the PC (via USB) or with another serial device connected to pins 0 and 1. And as someone else has said, with a little trickery you can do both. If you just want another device to see the Tx from Serial (pin 1) (one way comms) you don't even need trickery.

...R

so the six Uno PWM pins are sufficient for those six servos

PWM is NOT used to control servos.

Each station also needs a pushbutton input -- another three pins. Finally, I need a way to configure each station's servo movement on a one-time basis, and store the maximum movement in EEPROM. My original design uses a DIP switch, but maybe I can move that function to software, and issue commands over Ethernet.

Look at the EEPROM.

Take a look at the YUN it's meant for this kind of thing, (it's a combo of an AVR with a linux co-processor and e-net/WiFi) and works out cheaper.

Mark

with a little trickery you can do both

Hmmm..., it is only trickery if the electronics are not well understood. It does go against an "old wives tale" often stated in the forum.

holmes4: PWM is NOT used to control servos.

Now I'm really confused. My notes on servos say, "The input signal is a variable-width pulse. A short pulse is one endpoint, a long pulse is the other end and a pulse halfway between these two is the midpoint. R/C servos are designed to center on a 1.5 ms pulse and vary between a 0.9 ms and a 2.1 ms pulse. The pulses typically are sent every 20 ms."

I have written PIC code that controls servos by sending a stream of PWM pulses, with the width of the pulse setting the angular position of the servo.

I must have misunderstood the Arduino docs about servos. I see now that I did misunderstand the number of servos the Uno can drive. I thought it was six, but closer reading indicates it's only two.

Will you please explain how Arduino controls servos if not by PWM? Pins ~9 and ~10 are used in the example sketches, and I thought those were PWM outputs.

Thanks.

--- Mike

Now I'm really confused.

There are three types of pulse setups from an RC transmitter to a servo. The first is usually referred to as PPM (pulse position modulation). The rc tx sends a number of pulses to the rc rx. These pulses have a duration that corresponds to a desired servo position. These pulses are sent in a looping sequence setup where the pulse position in the sequence determines which servo gets that command. The rc rx is in sync with the sent pulses and sends a pulse of a specific duration to the assigned servo (usually in the 1000us-2000us range). The internals of the servo converts this pulse duration into a voltage value that will be compared to the voltage input from the servo pot. Depending on the magnitude of the voltage difference, the servo internals generate a pulse for controlling the internal motor H-bridge. The width of this pulse will be somewhere between 0% (full off) to ~100% (full on). The PWM used to control the internal H-bridge is of the same type that is used in the arduino analog out to control an external H-bridge or transistor. At least that is my take on it.

zoomkat: [...] The PWM used to control the internal H-bridge is of the same type that is used in the arduino analog out to control an external H-bridge or transistor. At least that is my take on it.

That is how I interpreted the books I read and the example sketches I looked at.

When I move from Ethernet testing to servo testing, I'll hook up an oscilloscope (and a servo) to pin 9 or 10, and see what comes out.

But for now, YAY! The Ethernet server works. My 11-year-old C#.Net program that used to connect to a TCP socket server on a Linux board connects perfectly to the Arduino. It receives ASCII characters and echoes them on the serial port.

This is moving pretty far off-topic (serial and power), so I better watch my step.

Thanks for all the helpful information.

--- Mike

MikeDodd: Now I'm really confused.

There are designated PWM pins on an Arduino that are intended for controlling things such as DC motor speed or the brightness of an LED. In this case the PWM is modulating the power available.

The signals to control a servo are generated differently and are available on any of the I/O pins. In this case the width of the pulse defines the position of the servo and has nothing to do with power.

It is unfortunate that PWM is commonly used to describe two very different processes.

...R

Robin2:
There are designated PWM pins on an Arduino that are intended for controlling things such as DC motor speed or the brightness of an LED. In this case the PWM is modulating the power available.

Yes; I understand how that works.

The signals to control a servo are generated differently and are available on any of the I/O pins. In this case the width of the pulse defines the position of the servo and has nothing to do with power.

Re-reading the Servo library docs today, I discovered where I misunderstood about how many servos one Uno can control. I thought it said that only pins 9 and 10 be used for servos, but now I see that, as you said, any of the I/O pins can be used. The docs also say that the Servo library disables PWM on pins 9 and 10. That should have tipped me off, but I missed it.

It is unfortunate that PWM is commonly used to describe two very different processes.

…R

indeed it is. I need to look over the PIC code I wrote five years ago. It moves two servos fine, but I’m not positive the pulse width is the only criterion – maybe the pulse position in the frame is a factor.

No matter… If the Uno can control 12 servos, I’ll abandon the PIC for that role in a heartbeat. :slight_smile:

Thanks for your comments.

— Mike

MikeDodd: maybe the pulse position in the frame is a factor.

The "position in the frame" is used by R/C transmitters to send data for several servos. It sends a number of pulses (one for each servo) within a single 20ms time slot. The order of the pulses is always the same and that allows the receiver to know which pulse is for which servo. The servo is not aware that the grouped pulses or "frame" existed.

...R