Hi, I was on here earlier asking about the control commands and such for the TReX Jr.
Now I am experimenting with using a BASIC program though a BASIC Stamp microcontroller.
I have used this before on Boe-Bots, and I know how to send commands with the SEROUT command.
My question is, if I want to sent the TReX commands through the BASIC Stamp, I would use this command:
SEROUT 1, 84, [???]
The “1” is the output pin and “84” is the baud rate. What I want to know is, what do I sent in the brackets if I want to sent it a command? In other words, what format does it sent the command in? ASCII, Hex, Decimal, Binary?
The SEROUT command sends the numerical values of the numbers you put between the square brackets. You can specify these numbers as decimal (base 10) by simply writing them out as you would normally, or as hex (base 16) by putting a $ in front of them. Please see the following for documentation on the TReX Jr commands.
For example, to set motor 1 forward at half speed, you might use:
SEROUT 1, 84, [$C2, $40]
SEROUT 1, 84, [194, 64]
SEROUT 1, 84, [$C2, 64]
All three statements above produce the same result.
Now there are a few things you should note about using the TReX Jr with the basic stamp. The first is that the TReX Jr ships with a default baud rate of 19.2 kbps whereas the baud parameter of 84 in your SEROUT commands corresponds to a baud rate of 9600 bps. You will need to adjust this parameter so that your basic stamp is communicating at a baud of 19,200 bps. Once you’ve established communication with the TReX Jr, you can change its baud rate.
Also, the Basic Stamp cannot receive serial information while it is transmitting or immediately after, as during this period it is reconfiguring its transmit module to be a receiver. The TReX Jr responds to data query commands more quickly than the Basic Stamp can handle. For example, if you ask the TReX Jr for the status byte, it will send it to you before the Basic Stamp is ready to receive it. We have released a firmware update (version 1.1) for the TReX Jr that will slow down its serial responses in order to allow it to work with the Basic Stamp.
OK, thanks. I have the baud on the TReX set to 9600 bps, and 84 for the BASIC Stamp. I installed the new firmware and sent the TReX Jr a command. Nothing happened. Any Ideas?
P.S. I sent it “Serout 0, 84, [$C2, $7F]” to turn the motor on full speed.
There could be a number of reasons why you didn’t see any effect. Do you have your Basic Stamp connected properly to the TReX? Is the TReX in serial mode? Are you sure the TReX is configured for 9600 bps? Do you have a way of checking to see that the Basic Stamp is indeed sending out what you think it’s sending (e.g. can you look at it with an oscilloscope or connect it to your computer via a USB-to-serial adapter and see something appear on hyperterm)?
I recommend you start your tests by using a simpler command, such as the one to read the TReX Jr’s signature or interface mode. Send the single command byte and then see if the Basic Stamp gets a response when it tries to receive something back from the TReX Jr.
By the way, I assume you used the TReX Configurator program to change its serial settings and update the firmware, is that correct? Can you still interface with your TReX Jr as normal via the Configurator program?
I used the Configurator to change settings and upgrade. I will work on figuring it out tomorrow and post back with my results.
I hooked a serial cable from the BASIC Stamp to the computer and attempted to send serial commands and pick them up with a program called STerm. It worked. Then I hooked the serial cable back in to the TReX Jr and tried to get a signature and a motor current, neither worked. I used the DEBUG terminal in the BASIC Stamp software to try and receive the data bytes. Unfortunately, I got nothing. I think it must have something to do with the baud mode, but I’m not sure what. 84, for the BASIC Stamp BS2, translates to a 9600 bps true baud rate with no parity. I have the TReX set to 9600 bps with no parity and one stop bit. I have the v1.1 software installed on the TReX. It seems like it should work, but I get nothing.
Can you describe how you are connecting your Basic Stamp to the TReX? Are you using the TTL serial connection pins? Are you connecting ground? If your Basic Stamp is outputting serial data at the baud rate you expect and the TReX is accepting serial commands at that same baud rate, it seems that the only possible problem source left is the way you are connecting the two.
I have wires, which I have tested with a multimeter, from pins on the BASIC Stamp directly to a 3-pin female header. This is connected to the serial pins on the TReX. Not the TLL ones. I know everything should work because when I hook the computer through a serial cable directly up to the TReX and send it commands through the Br@y terminal and it works. I have it grounded to the Vss on the BASIC Stamp and the same cable connected to the ground on the TReX.
I’m not really all that familiar with the Basic Stamp, but I’m pretty sure it communicates using TTL (logic level) serial whereas a computer communicates using RS-232 serial (labeled COM on the TReX Jr). TTL serial ranges from a low of 0 V to a high of 5 V while RS-232 can be from a low of -12 V to a high of 12 V (so you need to be careful about what you connect RS-232 signals to as this can be out of spec for a lot of IC lines!).
Try connecting your Basic Stamp to the TReX Jr via its serial out (SO) and serial in (SI) pins as shown here in the user’s guide:
You should be making the connections shown in the lower of the two pictures (the one between the TReX Jr and the microcontroller). Please let me know if this gets things working!
I will let you know when I try that. I won’t have a chance until Monday when I go back to school.
It worked! I was elated when the motor actually turned on. haha.
So now I have some unrelated questions which I will put in a new thread.
Thanks a lot guys
Great, I’m glad to hear things are working now.