The Arduino output board
The Output Card – Arduino expand output port – up to 14 output pin for single ic for the home automation system built with Arduino
While not the heart of the system, this board has absorbed great deal of time writing software. This complex construction has resulted in a card suitable for a variety of applications that require timing. In practice, this card can be used in many circuits, from robots to anti-thielf and to create fantastic animated toys.
I tried to design a card capable of handling timing different styles (fixed, blinking, pulse etc.) and that we can be controlled simply with the I2C. A general card for use in a variety of projects.
The output board for Arduino is based on the CPU Atmega328 with Arduino bootloader. The software that I designed for this CPU waits for commands I2C and then sets the behavior of each of its 14 pins.
With these commands, each pin can be turned on or off, either immediately or delayed, for ever or for certain time. As you can see in the picture, the card is formed with three identical sections, each containing a CPU so as to address in 42-pin (3 ATMEGA328 * 14 pins = 42 pins total).
However you can add more, by increasing 14 pins for each CPU. Up to 8 CPU you can load the same software into each CPU because the I2C address is set with three analog pin (2^3 = 8). For each additional block of 8 cpu you need to change the variable that contains the starting I2C address.
In practice it will be necessary to load the program *. pde on the first 8 CPU. Then modify the variable with the source I2C address and reload the program to the next 8 cpu and so on for all groups of 8 CPUs.
An additional analog input is designed for zero detection. In the project to 14-pin output through a transistor, are connected to the relays connected to 230V. The negative characteristic of the relay is the generation of overvoltage when its switch contacts around the crest of the sine wave of 230V. This phenomenon as well as damage the relay contacts produce spikes (noise) that can affect the behavior of other electronic devices.
To minimize this phenomenon, the project has an analog input for the zero detection in order to calculate the best time to switch. The program is designed to wait 6ms from detecting zero before activating the relay. Given that typically takes 4ms to activate the relay, will have the that from the zero crossing to activation pass 6ms +4 ms = 10 ms that is precisely the time that the sine wave of 230V come back to 0V and so switch without current on the relay contact. To deactivate the relay instead, because they typically employ 7ms, the waiting time before release and then just 3ms.
But the above represents an ideal condition. This is because the zero-detection circuit can introduce a few ms of delay and the relays do not commute with the typical delay indicated. To overcome these problems it becomes necessary to modify the times indicated in the program *. pde up to minimize the ignition on the relay contacts (empirically on a statistical basis to do if you do not have measuring instruments suitable for this purpose). However, the card also works in the absence of an external circuit as detection of zero in each case the program after 15 ms (a cycle and a half) without zero pulse on pin detection switches anyway. The absence of a zero detection circuit is not recommended to connect equipment with a strong absorption of electrical power such as pumps, washing machines, ovens, etc..
But let us return now to the core behavior of the circuit. As mentioned timings are the basis of many electronic circuits. For example, anti-theft turn on for some time a siren or activate functions after a certain time to allow time for the owners to disable it before activating the sirens. Another example of the robot according to advance and retreat of the sensors activated by activating the motors for a predetermined time
> From this premise, the idea of a dedicated electronic circuit to turn on and off its outputs, and after a while, easily controllable through I2C protocol.
In particular, the circuit allows to control up to 14-pin lighting
- After a delay,
- Immediately for some time,
- After a delay, and for a time
The pin turn on style is varied and can be:
- On continuously
- A flashing light slow
- A flashing light speed
- A slow flashing light and fast in the last 5 seconds before switching off
- A single flash every 20 seconds
- A flashing light in sequence a flash every 5 seconds for 4 times and then 4 blinks fast.
- A flashing light flashes fast.
How it works
Using the I2C protocol is passed the command to the CPU that is responsible for managing all stages of the pin. To understand through the command //23580 you get that pin 2 (of 14 available) blinks slowly (command 3) after 5 seconds for 8 seconds after which the pin goes to 0. The description of the commands in the next section.
The animation on the side should give an idea of the operation. The I2C command comes along the bus represented by the red arrow. The CPU of the circuit starring the command, and then turn on the corresponding pin.
For clarity in this animation are not represented all possible commands.
The commands pass data on which pin turn, after the time, for how long and how the pin should be left to command end.
Looking at the graph, indicated by the instant t0 is the time when comes the command, the time delay is represented by t1-t0 (green color). The start time is represented by t2-t1 (blue) and the time t2 (red) is the time after the command.
The board accepts the command, make no changes to the pin which can be zero, or one, for all the duration of the delay time. Then turn on or off, depending from “StileLampeggio” value, and keeps the state for the duration of Pin “T accensione” and after set the pin to value indicated in the “StatoFinale”.
To create the commands you must use the following syntax:
/ / Pin StileLampeggio Tritardo Taccensione StatoFinale
(replace the contents between <> (included) with following table of values (in hexadecimal)
Two Char fixed
Pin number to turn on. Value from 0 to 13
Pin flashing style:
2=Swap state; if 1 set 0 and viceversa.
The command with 2 working but then no change state at the command end. Therefore the time can be set to any value other than zero.
The delay in second before the activation.
From 0 to 255 (255 equal to 4 minutes and 15 second).
The on state time
After how many seconds the pin back to the precommand state.
From 0 to 254 seconds. Always on if set to 255.
Attention. Set the value to 255 means always on.
Command with this value equals zero has not effects.
The final state at the end of “T ritardo” + “T Accensione”:
0=At the end go to zero
1=At the end go to 1
2= Returns at the pre command state.
This value is ignored if “Pin Lampeggio”=2 (A change state is make only one time at the end of “Tempo Ritardo”)
Now any sample (The value in <> must be hex: <255> equals a byte with all bit higth. Least Significant Bit on right).
|Command||Description||Pin out state|
|//<13><1><0><255><0>||Get the pin 13 (<13>), switch it on (<1>), immediately (<0>), and keep it on (<255>).|
|//<6><1><5><25><0>||Get the pin 6 (<6>), Switch it on (<1>), after 5 seconds (<5>), and keep it on for 25 seconds (<25>) and then turn it off <0>.|
|//<7><2><0><x><0>||Get the pin 7 (<7>), Change its state; If on, turn off or if off then turn on (<2>), immediatly (<0>), and leave it in this state independently the last command byte <x> that can assume any nonzero value. For “Pin Lampeggio” = 2 the “statofinale” is not necessary However, it is necessary to supply a value.|
|//<3><2><5><x><0>||Get the pin 3 (<3>), Change its state; If on, turn off or if off then turn on (<2>), immediatly (<0>), and leave it in this state independently the last command byte (<2>), after 5 seconds (<5>), and leave it in this state independently the last command byte <x> that can assume any nonzero value.|
|//<3><5><5><8><0>||Get the pin 3 (<3>), active on it the fast flash <5> , after 5 secondi (<5>), e per 8 seconds <8> and at the end set it to zero.|
|//<3><5><5><8><1>||Get the pin 3 (<3>), active on it the fast flash <5> , after 5 seconds (<5>), and flashing for 8 seconds <8> and at the end set it to 1.|
should be considered:
1) in case of overlapping commands, the last valid command to a specific pin replaces the previous command.
2) has no effect turn on a pin-by-zero second, so all commands that start-up time as the value zero are immediately ignored.
3) You can send //****0** to invert the output level. In this manner the pin goes to 0 when it turn on and remain to 1 when is off. Sending //****1** to get the pin in normal state (no inverted).
Now for the circuit. Use three ATMEGA328 CPU with Arduino bootloader. Each CPU has its ATMEGA328 and only a few external components are required for make it work, the 16Mhz quartz, and two 22pF capacitors the inevitable capacitive filter consists of two capacitors 100.000pf close to the CPU. Finally, a resistor and LED connected to each output pin for visual status indication the pins.
The simplicity of the circuit is due from the fact that all functions are performed by software loaded into the CPU and partly because the CPU is free of any additional part such as the hardware USB communication, the lack of which forces the software to load the CPU board using a Diecimila.
How to make the card
Printed circuit board and replicated it on a breadboard. Try to strict compliance with the measures arranging the pieces exactly as indicated. Started to weld the pieces beginning with the lowest parts. Arm yourself with patience to connect all the wires needed. I have used and personally recommend wire recovered from a multi-pair telephone cable to the whose strings are colored and have a sufficient strength and rigidity which facilitates positioning during welding.
How to load the sketch to ATMEGA328
To load the software on these chips must be used to the card Diecimila. From this you must remove the CPU from the socket using a small flat screwdriver and then placed above each other CPU to program.
Prepare a computer connected via the USB Diecimila with Arduino IDE software can be downloaded from www.arduino.cc download section (at this time is at the 0022 version).
Load in ‘Arduino IDE the program .PDE (the program is called Sketch), support the cpu with ATMEGA 328 Arduino bootloader (it purchase on the Internet at a cost of about EUR 6 each) on board Diecimila (hold it with one finger so that all pins make contact but do not push it fully into the socket so as to remove quickly after programming) and finally, on the IDE, click the icon with the right arrow to load the software on the CPU ATMEGA328. Repeat everything for each CPU, and insert it on the output card.
After these operations, the card is ready. To test, use a another Arduino, to pass the I2C commands and see the LEDs connected turn on.