I needed to get the sensor closer to the wheel spokes
in order to get more light reflected onto the sensor,
allowing me to better discriminate between the spokes and
the spaces between the spokes. I keep a stock of
We can clearly see that the “spokes” reflect light, and
are a lot narrower than the space between the spokes
TCRT5000L reflective sensors, so I just needed a way of
wiring them up and attaching them appropriately.
To keep the sensors small, I used male-female DuPont
jumpers over the legs of the TCRT5000L sensors (Figure 7).
I then used one of my prototyping boards to add the
resistors, and more DuPont male-female jumpers to run 5V,
GND to the board, as well as run the two analog signals
back to RoboPi.
There is plenty of space left on the prototyping board if
I decide to add an op-amp to increase signal gain, or any
other circuit to improve the encoder’s performance.
Calibrating the Encoder
It’s time to write a calibration utility to find the
minimum, maximum, and average light level reflected by
pi@Berry:~/robopi/Python_Demos python berry.py
Berry Encoder Calibration Test
Testing the New Encoders
I hooked everything up, and started with a small test
program that ran both of the motors that I attached
sensors to at full speed, printing out the analog reading
shown in the figure from the phototransistor in the
Capture of 500 samples took 11.1943240166
Analyzing Motor A data...
Motor A min 87 avg 152 max 301
TCRT5000L (Figure 8).
Analyzing Motor B data...
Motor B min 94 avg 153 max 327
Motor A calibration value is 152
Motor A calibration value is 153
If you change motors or the position of the encoder
sensor, you need to recalibrate.
Okay, now that we have the calibration values, we can
decide if a spoke is close by.
Let’s add code to count the number of “high” and
“low” periods for the length of the test run.
High and low periods are counted as follows:
- If we are X% above the average, we are in a HIGH
38 SERVO 02.2017