Thursday, August 18, 2016

Adventures in Radar with the Raspberry Pi (Part 2)

This is a continuation on a previous post, which you are advised to read first.

"It came!  It finally came!" -Sid from Toy Story.  Also myself.

Alright, lets rip this shit open!

Well this is embarrassing... I did not mean literally!  I had a lot of trouble with drilling out the screw caps, which was compounded by the fact that the cheap plastic was also very brittle and kept "grabbing" the bits.  I could have done this really cleanly with a drill press but since I was drilling freehand the bits kept pulling and stripping screws.  Since the whole process was going to disastrously anyways, I ended up just tearing it apart.


Pay no attention to the huge dent in my waveguide from the drill bit!  Hopefully it won't affect anything too much...

So we have the RF TX/RX module with a waveguide soldered to it.  Then there is a little PCB with the screen and buttons on it.  Finally there is the end of the battery holder with a dual pole dual terminal switch for the trigger.


Here's a picture of the back of that battery holder/switch assembly.  There are two sets of wires, Brown and Blue.  It looks like when you pull the trigger, the blue wires are bridged to take a reading, and when you let go, the brown wires are bridged to report the highest captured value.  I've already ripped off the black and red positive and negative terminals from the battery connector.


Here's a closeup of the board and the radio module.  There are only three wires going to the radio module, red, black and white.  Black is ground, white is "SIG" (our Doppler shift signal), and red is "VOSC" which I can only venture to guess is "voltage oscillated".  This is important because I vaguely remember that some devices are "pulsed" as opposed to a continuous wave.  I'd be worried that taking out this board would then change the way the radar module operates.


I powered up the device with some alligator clips and waved by hand in front of the waveguide and it registered 512 miles per hour.  That did not seem right.  Then I remembered that red switch on the left controls "Scale", so that you can radar a hotwheels car and figure out how fast it would be going if it were the size of a real car (it just turns on a 64x multiplier for speed).


This seems more reasonable.  Obviously you have to push and hold the button (simulating a trigger pull) to get real-time readings, and highest speed is reported when you let go.


Alright, time to solder some breadboard leads onto the wires that used to go to batteries.  If you solder but don't have a set of "Helping hands", get one.


Seeing as how everything seems to work, I then soldered a breadboard wire onto the SIG connection to try to tap into the signal coming out of the radar module.  This picture courtesy of the magnifying glass on my "helping hands" that I was repping above.  Unfortunately the GPIO input of the PI did not register anything.  I hooked up a volt meter which will only give a rough idea because I'm checking the voltage of sine wave (I guess) and only picked up about .04 volts.  Bummer, I'll need to figure out how to get that up to something reasonable to get the pi to read it.  Feeling defeated I gave up for the day.

BRO OF THE WEEK AWARD

goes to "Zerodegreec" for his contribution in reply #7 of this post on the arduino forums seen here:
This is super exciting because this "test point" he's referring to leads to the signal from the radar unit AFTER it's been amplified.  I took a reading on it and it seems to output over a volt which is 20x more power than I was seeing from the SIG wire out of the radar module.  I don't know if there is a way to directly convert the reading of a voltage of a frequency, but "more" is good enough for me to get my hopes up!  Also notice in this picture that a brown wire was added to go to the ground of the ATmega644 that was connected to the test point; I did not need to do this because the pi and radar module are being powered by the same 5v power source (the USB battery) with a common ground.


I soldered a breadboard wire to the "test point" on my board.  It's on there but barely.

There, much better!  The hot glue that came on this thing is obnoxiously effective so I added some of my own.

Since 5v into the pi's GPIO will release the magic smoke (I'm feeding this board 5v), I tried first with a 1k resister, the same size that I was using to drop the 5v signal to about 3.3v on the old radar module.  I connected the the lead on the other end of my resister to the pi, pulled the trigger, waved my hand in front of it and hoped for the best!


Neat!  Except for that last reading which must be an anomaly.


This is a capture of me walking towards the module.  According to wikipedia, the average human walks at 3.1 mph.  The average human however isn't usually carrying a laptop and walking like an idiot while being overly conscious about trying to walk a normal speed.  What I noticed is that when nothing is really moving there are virtually no readings, and this is awesome.  The previous radar module I tested had tons of background chatter, so much so that I told my script to only output readings over 3 mph.  Lets try something a little faster...



I figured a flap made of foil tape on a bike tire rotating in the path of the RF would give me some kind of reading.  With the bike upside down I turned the pedal for a bit and pulled/released the trigger button so I could compare the top speed the radar captured with the top speed my script captured:


Seems pretty close to me!  The samples are really poor as it's a small target but the LCD reported 25 and my pi reported 27.07.  I'm wondering if the fractions of miles per hour are the Doppler shift of the wheel vibrating or something.  It's time to find something with a little more consistency.


I pointed the waveguide at the fan in different angles until I found one that the value didn't fluxuate much at all.  Some angles I was getting up to 40mph (with very poor consistency) which makes sense because the amount of Doppler shift is going to be affected by your angle of reading due to the cosine effect.  I started getting a really solid reading that was showing 12 miles per hour on the LCD screen.



Look at that!  Those are some solid readings!  I tried a few different tweaks and it seems like the best results were sampling the signal and waiting for it to decrease in voltage twice, and finding the time between them.  Then I averaged three such readings to get a more consistent speed.  I might not even need to calibrate as this radar module is 10.525Ghz just like the last one, and thus the same equation of 31.36Hz per MPH still seems to apply.  I'll probably still need something to remove the occasional anomaly though I only saw that when I had my hand within a few inches.


My current code.  When you call the "getspeed()" function, this is what happens in a nutshell:
1.  Wait for the GPIO voltage to be falling (signal wave dropping)
2.  Set the variable "start" to the current time
3.  Watch for the wave to drop two more times
4.  Subtract the start time from the current time to get the "duration"
5.  Divide the number of cycles (samples) by the "duration" to get the frequency in Hz (or waves/sec)
6.  Divide the frequency (in hertz) by 31.36 to get "speed" (miles per hour)
7.  Return said speed

So in the while loop I'm just adding the result of the getspeed() function three times and dividing by three to get an average.  I also have another IF statement below to take a picture if a certain speed is exceeded (not pictured).

What's next?
Now I need to put everything else together.  My plan is to get a DPDT (dual pole dual terminal) relay for the trigger assembly.  This will basically give me a relay that when I power the coil, it will take a radar reading, then when I stop powering the coil it will revert to the "highest" state (remember the trigger has two pairs of wires going to it).  That will allow me to have the LCD screen output the highest captured value after a sample, so that I can compare it to the highest value returned by the pi to see if they match.

How will I toggle the relay?  I've been experimenting with some HC-SR501 Passive Infrared Motion Sensors.  They have a 3.3v output that I should be able to run straight into GPIO and sense when they are triggered.  here is one that I was using to light up an LED when there is motion:


So my idea is that the pi will be alerted to motion when the PIR is triggered and sends a 3.3v signal to the pi via GPIO.  Then the script, having sensed the motion, will start listening for signals from the radar module while simultaneously outputting 3.3v to a different GPIO pin going to a mosfet that will turn on the power to the radar module.  After capturing a few seconds of signal from the radar module the pi will use the highest one using the "max()" function, and I can compare that against what the LCD shows as the highest value captured.  The range of the PIR is only about 7 meters so I might want to have the radar measure targets as they leave AFTER the PIR motion sensor detects them passing by.

Well that's all for now!  Hopefully you are smarter now!

1 comment: