I am new to the Basic Stamp and Trex Jr and am trying to write a program that will control the motion of three motors, but I am strugling to get even one working.
Below is my breadboard setup:
The Basic Stamp is connected on pins 1-4 to pins 2-5 of a DB9 serial to USB adapter and is powered by the 5V out pin of the Trex Jr, the Hello World runs fine.
I guess my problem is due to not knowing where to plug the SO/SI of the Trex Jr into the Basic Stamp 2, if I just plug the green one in port 10 (pin 15 as shown) and run SEROUT 10,19200,[194,127] (19,200 is the default baud rate at which I can operate the Trex Jr via a direct DB9 connection) nothing happens.
Any help will be much appreciated as the documentation of the Trex Jr is really lacking detail.
I am not very familiar with the Basic Stamp 2, so I could be wrong, but I do not think you are using the SEROUT command properly. My understanding is that the second argument (the one after the pin) is not the baud rate in bits per second but rather is an encoding of the baud rate along with other serial parameters, such as the number of bits, the parity, and whether the serial is inverted or not. I don’t know what you mean by “the Hello World” runs fine, but if you are getting serial communication via a DB9 connector, you are likely set up for RS-232 (inverted) serial.
If you are using inverted serial, you need to make your connections to the RS-232 serial pins (RX and TX). If you are using non-inverted TTL serial, you need to make your connections to the TTL serial pins (SI and SO). This is covered in the user’s guide; can you tell me what details you think it is lacking?
As per this post (BASIC Stamp Control) I adjusted the baud rate of the Trex Jr to 9600 and am able to put in motion the motors via the RX/TX pins.
However, I am not able to set the motor in motion with Basic Stamp 2 either via the SI/SO or the RX/TX pins and adjusted the command to SEROUT 10,84,[194,127].
Where do I have to plug the RX/TX jumpers into the Basic Stamp 2 if I am using inverted serial and I want to send commands through port 10 (pin 15) to the Trex Jr?
The Hello World means I am able to run commands on the Basic Stamp.
Are you saying you were able to use your USB-to-serial adapter along with the TReX Configurator Utility to change the TReX Jr settings and drive the motors? As I said, I’m not all that familiar with the Basic Stamp, so I can’t give you too much help on how to write code for it or make your connections. However, if you can communicate with your computer using serial from the Basic Stamp, and you can communicate with the TReX Jr using serial from the computer, you should be able to figure out how to eliminate the computer and connect the Basic Stamp directly to the TReX Jr. The serial parameter 84 produces non-inverted serial, so you would need to connect to the SI pin.
Yes, I am able to connect the Trex Jr Configurator to the RX/TX pins, make configuration changes and drive the motors. I have no problem connecting the Basic Stamp 2 to the Basic Stamp Editor and run commands, but when I send SEROUT 10,84,[194,127] and connect the Trex Jr SI pin to I/O pin 10 (15th on the schema) the command does not set the motor in motion.
I suggest you disconnect your motors for now and just use the motor indicator LEDs as feedback. Also, can you try using our serial transmitter utility to send those same two command bytes at 9600 baud (using the same connections as you did with the TReX Configurator Utility)? If it doesn’t work from the serial transmitter utility, there’s a problem with the bytes you are sending and you need to figure out what the Configurator Utility is doing different. If it does work, then you need to figure out what your Basic Stamp is doing differently. Perhaps the Parallax forum can help you figure out what line of code you need to produce the same output as your USB-to-serial adapter so you can make the same connections with your Basic Stamp instead.
I disconnected the motors connected the USB-Serial to the RX/TX pins and then sent a 2 byte command [194,127] the output from the Serial Transmitter was:
11:57:23 AM sent C2 7F
received: C2 ‘Â’ 7F '’
There is a missing square in the quotations after 7F, but the motor 1 lights did not even blink.
When I send just 0x81, I receive the expected response.
Actually after a few power cycles in attempt to get the Pololu Serial Transmitter to work, I went back to connecting the Trex Jr to Basic Stamp 2 and sent out the same command as above and it was sent to the Trex Jr and set the motor in motion.
Thanks for the help.
I’m glad to hear it’s working. You need to cycle power on the TReX Jr before certain changes will take effect. Changes to the baud rate are one example of this. Also note that serial connections to other powered devices can keep the TReX Jr from properly resetting by powering its microcontroller through the serial I/O line, so I recommend disconnecting anything connected to the SI or RX pin before trying to cycle power.