The MagPi - July 2018

(Steven Felgate) #1

Tutorial WALKTHROUGH


(^46) July 2018 raspberrypi.org/magpi



STEP-02
Adding access holes
The BNC socket has a flat on each side of the
thread, this is to prevent it rotating with the
twisting force it will be subjected to upon
connecting any probe. We did this by first
drilling an 8 mm hole for the flats and then
enlarging the hole with a circular file on each
side to allow it to fit. An 8×12 mm hole was filed
opposite the USB connecter to allow access.
switchable attenuator fitted, thus allowing voltages
of +/- 25 V to be measured. Full construction details
can be found in the numbered steps.
Arduino software
The software, or sketch, you need to put into the
Arduino is shown in the Gather_A0.ino listing,
and is quite simple. Normally an Arduino of this
type will take samples at a rate of 10 000 per second




  • or as we say, a 10k sample rate. This is not too good
    for an oscilloscope, but we can increase this sample
    rate by speeding up the A/D converter’s clock speed
    from the default rate. It does not appear to affect the
    reading accuracy too much. By making this change,
    we can speed up the sample rate to 58k. This is much


better and allows useful measurements to be made
in the audio range.
So, first, the trigger function is optionally called
and then the samples are gathered in and sent to the
Pi. The trigger function has a time-out which means
it will trigger anyway after one second, whether it
sees a transition on the input signal or not. Then the
three pots are measured and also sent to the Pi. Note
here that the samples are ten bits wide and so have to
be sent as two bytes that get joined together again in
the Pi’s software.
Also note the use of the double read for the pots,
with a bit of code between each. This ensures a
more stable reading as the input capacitor of the
Arduino’s sample and hold circuit needs time to
charge up, and it has less time than normal to
do this due to the speeding up of the D/A. It does
not effect the waveform samples too much as in
most waveforms one sample voltage is close to the
previous one.
At the end of the transfer, the Arduino sits in a
loop waiting for an acknowledge byte from the Pi so
it can start again. This acknowledge byte also carries

It proved to be a lot more


tricky to write than we


first imagined

Free download pdf