I am trying to build a GPS guided wild thumper. I have invested in some hardware and have been mucking about with it for a while now. But to be clear, I am a beginner.
This is what I have:
-Raspberry Pi 2 with a NoIR camera
-T'rex Motor controller (Dagu)
-The 4WD Wild Thumper Chassis
-nRF24L01+ radio controller x2
-SKYLAB SKM53 GPS unit
-A Couple of SR04 Ultrasonic distance units
-A Battery 7.4 LiPo
-Bi directional level shifter 3v3 to 5v
-A few other sensors I wanted to stick on the thumper...
My original thoughts were to use my Raspberry Pi2 as the control centre... this is how I intended to do it:
- RPI I2C bus (Master)---> T'rex motor controller I2C (Slave) (ehem!)
- RPI UART ----> SKYLAB GPS
- RPI GPIO ----> SR04 (With appropriate voltage divider)
- RPI GPIO ----> Lights/Other sensors (With appropriate voltage divider)
- RPI SPI -------> nRF24L01+
- RPI NoIR camera
My first attempt has so far been rather disappointing ...
Turns out there is a clock stretching issue with the RPi (That has not been fixed since the first version of the RPi). There are software solutions which I have tried, that give me variable results. The I2C bus hangs/drops , slowing down the RPi's clock works somewhat, but still occasionally hangs the arduino(T'rex controller), unless the arduino's code is efficient enough to keep it up to the speed of the RPi (Which the current, quite elegant code-- by Odbot, doesn't seem to do). I've attempted to simplify the code, and with some slowing down of the RPi's I2C clock, have had some (but unsatisfactory) success. I would like to have a more stable way of operating the robot. I would also like to keep the RPi as part of my setup.
One suggestion/solution I came across was to hookup the serial port on the RPi to the serial of the T'rex... which is certainly a solution I will try... However, don't I then loose the pins I would need to hookup the GPS (which has a UART)? ...
So the question is, after dumping the use of buggy I2C pins on the RPi;
How do I keep the GPS, AND connect the RPI through a serial port to the T'rex?
Can I connect the GPS directly to the T'rex (Since I'm going to attempt to communicate through serial?), THEN connect the RPi to the T'rex?
Is there a way to also connect the nRF24 module to either the T'rex or RPi and get them to all sing together in harmony?
Without buying any other components, How would you do it?
If you would buy something else... what would it be? (an FTDI USB might work???)
Any help is much appreciated.
The clock stretch, if implemented correctly on both ends, should allow the slave device to regulate the clock speed by holding it low until it is ready to proceed. I am unfamilar with the I2C scheme used on the T’rex controller. Is it hardware or software?
I am confused about your intended use of the nRF24L01’s. Are you thinking of making the RPi a “base” station and having the motor controller only on the chassis?
I’m sorry I should have been
I’m sorry I should have been clearer. I’ve made an arduino powered radio controller using the nrf24 for short range control. The pi is directly connected to the t’rex and I’ll secure both to the chassis. The t’t’rex is essentially an arduino nano with an h-bridge and some other stuff like an accelerometer etc. As far as I understand the clock stretching issue is a hardware bug on the pi. It should wait for the slave but it doesn’t. I can slow down the pi ’ s baud rate relatively easily. You can read more about the pi’s i2c issues here. https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=13771&sid=0e60d3a1c3b81761e4159eeefd912ff4&start=50
Basically the I2C isn’t properly implemented on the raspberry pi.
Of course the easy way out is to dump the RPi… but why take the easy way out right?
Last entry in that article states:
“pigpio has in-built bit banging of I2C. It supports clock stretch and repeated starts.”
I don’t know how to implement that… yet … (I’ve been a little lazy about that to be honest, I’ve got a biotech background soo things are a little steep at the moment)
I have found a temporary solution though… I found a USB to TTL dongol and connected it to the GPS. Seems to be working ok so far… Still have to put everything together. On to learning about serial… Thanks
** bit banging of I2C**
OK i’m taking your advice and I’m looking at pigpio.
I’ve downloaded it and read a little more about bitbanging. It’s a little beyond me. I keep reading that I need to install pullup resistors to 3v3 for the pins I’d use (not something i’ve done before). I’m wondering if I can use the actual I2C pins (which appear to have pullup resistors) to do the bitbanging (since I don’t have a breakout board with resistors installed)?
Most modern CPU’s have an option to enable/disable internal pullups on some I/O pins These builtin resistors are typically in the 20K range. They may work if you have a single device and short wires. Many I2C board level modules either support jumpered, soldered, or always active 4.7K pullups (not always clearly speced). The “ideal” I2C pullup is about 2K 5V bus and 1.4K for 3.3V bus. Two 4.7K peripherals is similar to a single 2.35K. T’rex dosent say so I would recoment an email to Oddbot.