Introduction: InterActive 1

Picture of InterActive 1
Life needs interaction to live. Machines need programs to interact with us. Programs need connectivity to grow more complicated. Serial communication is what machines use to grow. Serial communication is built into most processors. That is how you first program them and debug them. Serial connections let each part of a machine talk to the other parts to make the machine do more complicated tasks. People love interactive things. Serial connections let you make your machine interactive. I will show you an example of an interactive machine using my EasyLights and buttons.

I had trouble getting messages between the Basic Stamp 2(BS2) and the Basic Stamp 1(BS1). The BS2 is about four times faster than the BS1. The BS1 locks up waiting for the BS2 message. The BS1 cannot see the BS2 message in the 200 millisecond(ms) window it has to check for a message. This is exactly why there are so many flow control lines left in a standard serial connectors. Slower machines can’t see faster ones. I needed flow control, but I didn’t want to use another port for it. I have an electronic background so I looked at the Rx and Tx as ports not just as serial connections.

Steve’s Flow Control uses the Tx port as flow control. You hold your Tx ports high with a resistor of 47K to VDD and in your code. You monitor your Rx port to detect when someone lower its Tx port. When you want to send a message you bring your Tx port low and then you wait until the receiver lower its Tx port and then you send your message. The receiver should stay in a tight loop waiting for the message. After the message both systems raise their Tx port high and go back to waiting.

For the BS1 and slower systems I lower my (Master)BS2’s Tx port and pause about 80 ms and then I transmit my message. The BS1 looks for a low on its Rx port and pauses 1ms and then opens SerIn for a two byte message. The first byte is the Address and the second byte is the Lights. If the Address is not correct the BS1 skips the message and goes back to waiting. The BS1 is too slow for full handshaking. It works perfectly with correct timing.

I can only send one message to the BS1 in every ten loops of my BS2’s code. I am running EasyLights in my BS2 and sending the lights byte to the BS1 that only has doLights and checkLights and a message loop. See my EasyLights article.

I could not get the BS1 to send a correct two byte message. The first byte is garbled and I do not know why. The BS1 can’t use my standard two byte messaging(Address, Data) so I am using a separate serial channel to handle this type of slave. The BS1 lower its Tx port and waits until the Master lower its slave Tx port and then the BS1 sends a one byte message containing the button flags to the Master. They both raise their Tx ports high and go back to waiting.

Working with the BS1 I decided to make them polled slaves. I simply keep them alive by constantly sending them messages. They do all of their work inside their message loop. There is no room for much else. They just sit there and wait for a message so their buttons and lights are in effect dead. Polling them keeps their buttons and lights alive.

As I get things done I will upload another part to this interactive article.

Planning is the first thing you must do to create an interactive machine. I wrote this document first and used it to program my processors. Since we need Serial communications we see what each processor has for its Serial functions SerIn and SerOut.
Arduino Uno                                         Full Serial                         Qualifiers                                   9600
Picaxe 28x2                                          Full Serial                         Qualifiers                                   9600
Basic Stamp 2(BS2)                           Full Serial                         Qualifiers                                   9600
Basic Stamp 1(BS1)                      Partial Serial            In Only Qualifiers                                  2400

Full Serial means in and out standard Serial. I am not using anything complicated.

Qualifiers allow addressing of the processors. Devices like serial e-proms have physical addresses. Qualifiers wait for the correct key before continuing with the message and on some systems this can raise an error that kicks it out of the message. Qualifiers let you have multiple Masters and hundreds of Slaves. On systems like the BS1 are too slow for anything but basic two byte address, data message. You can still do a lot with this simple form of messaging.

Baud Rate(9600) is the speed of the flow of data between the devices. Processors like the Basic Stamp 1 can only go to 2400 so you must use that speed with them.

The one that transmits first is the Master the others are receives. One Master is best, but more Masters are better. Qualifiers and addresses let you do this.

In my system my Arduino Uno is Master 1 and my Picaxe 28x2 is Master 2. The BS2s can be good Masters for lights and buttons, but they are Master/Slaves here.

I have my Arduino Uno connected by the programming cable to my PC. I am using the debug terminal to monitor and control the other processors through just Rx and Tx and Ground. A very simple way of creating an interactive machine.

This article is growing.

The Address is a number(qualifier) that you set up for each processor and device you have. My address is a byte formatted like this Type(Bits 7-6) ,  number(Bits 5-0). Qualifier or address is the first byte you send to another processor or device to open a message with it. All messages fully terminate after the last byte is sent. To send multiple bytes to a receiver you send it a command that tells it that more bytes are coming. Basic Stamps are from Parallax.com.

Type  Master(128),  Master/Slave(64),  Device(192),  Slave(0)
Number                 0 – 63               Bits 5 - 0
Arduino Uno             128                Master(128) + 0                                          Makezine.com/Store
Picaxe 28x2                65                Master/Slave(64) + 1                                  LetsMakeRobots.com
BS2 PJ1                      66                Master/Slave(64) + 2                                  Basic Stamp 2 Project Board
BS2 SC1                     67                Master/Slave(64) + 3                                  Basic Stamp 2 Super Carrier
BS1 PJ1                        4                Slave(0) + 4                                                  Basic Stamp 1 Project Board
BS1                                5                Slave(0) + 5                                                  Basic Stamp 1

Connections are TX(transmit data), RX(receive data) and Ground. If you power your slave from your processor than you need power too. Most serial connections also need pull up resistors on TX and RX of at least 20K. Usually its 40K. See your manual for your processor. All of my boards are 5 volts. In my system the Master/Slaves like the BS2 use another serial channel to run BS1 slaves. This keeps the main serial channel clean.

Your cables need to be twisted-pair about two twists per inch. If you go more than about ten feet then use shielded twisted-pair cables. Avoid power/extension cords, transformers, motors and other electrical things. The data is asynchronous that is it has an internal clock and that makes it more susceptible to noise of any kind. Having a good power supply and lots of big capacitors helps a lot.

Rx(SerIn) and Tx(SerOut) are the ports you choose on your processor boards:
Master        Flow                     Slave                              *PC                              My cable
Rx                <<<                        Tx         22k resistor     TD                               Black
Tx                 >>>                        Rx        22k resistor     RD                              White
Ground                                      G                                      G                                Green
Power                                        V+                                    X                                 Brown

I keep most of my cables straight Tx-----Tx according to my Master. This keeps confusion out of breadboards and processor boards. For connections to PCs and things you connect Rx and Tx to the correct pin/connector and wire that they belong to for that system.

*PC serial uses inverted protocol in most cases.
Start Bit and Stop Bit refer to their bit position in the serial stream as message flags and control.

One key to a machine is a status byte or word that gets everyone talking on the same page. I am using a byte. Status can be the first byte sent after the address. Status can also be basic commands into the other processor or device. This makes standard two byte messages easy.

             Status                      on                      off                      Sent back
             Bit0                          OK                  Busy                        D1
             Bit1               Message                 Done                        D2
             Bit2                  Waiting            Running                        D3
             Bit3                      Mode                    Stay                        D4
             Bit4                       Data                   none                        D5
             Bit5                     Reset                                                    D6
             Bit6                     Cmd1                                                More
             Bit7                     Cmd2                                                Done

Organization is the first step to a working machine. Working with Bits is what processors do all of the time. We need help with Bits. You use the logical operators And, Or and Shift to work with Bits. Anything above 63 is a Master. First save the byte then shift it right 6 bits for the Type. Save the address by address = Anding it with %00111111.
          Type = address >> 6   Address = address And %00111111

Lay all of this into constants at the beginning of each program. Keep everything updated and you will get a working machine. Bad Serial programming shows you nothing. Label everything so you know what it is doing.
 

Comments

About This Instructable

810views

2favorites

License:

Bio: I have always been a geek and I see things differently than most people. I am healthy too and I love biology. Programming has always ... More »
More by Geek07Boy:Fun Led Checker TesterFlying a toy QuadCopterServo Math
Add instructable to: