SWIFT, RASPBERRYPI, BLUETOOTH — X — FILE PART 3

PROXIMITY SENSORS

As already written in the first article this is the second prototype, the first revision of the hardware used

SENSOR CHARACTERISTICS

As proximity sensor I used this protoboard based on TCRT5000 chip, made by phototransitor sensitive to IR light, it has 3 pins VCC, GND and OUT. They have an IR emitter that emits light and a phototransitor receiver. If some light is reflected into the receiver it react with a zero value on the OUT pin.

MOUNTING THE SENSOR

To mount the sensor and the led I’ve decided to create 3d printed housings that will be inserted inside the target, this has also required to cut two windows inside each target:

3d printed housing
Housing with embedded sensors and leds
Punching bag with windows
Punch bag with sleeve and windows

CALIBRATING THE SENSOR

To calibrate the sensor a sheet of white paper was used over the surface of the target, measuring the output until a zero value has been received from the sensor OUT pin at the correct distance.

LED

Leds are RGB 4 pins leds (R,G,B, GND) that can be controlled using PWM to make different colors. To use less wires as possible and make things easier, since I need only 6 colors, I just used a single output pin from the Raspberry to drive one or multiple input of the led by connecting them to each other .

SOLDERING

To create plugs I’ve build a small board that takes the GPIO pins from the Raspberry and transform them into easy plugs one for each target.

Soldered board with plugs and buttons

LAUNCHING THE SOFTWARE AT STARTUP

To launch the software at the startup we first need to make it executable.

swift build -c release
  • modify rc.local
  • use crontab
  • name of the service
  • startup service dependencies
  • the command
  • installation target
[Unit]
Description=Punch service
After=bluetooth

[Service]
ExecStart=/usr/local/bin/PunchBLE
[Install]
WantedBy=bluetooth
sudo systemctl daemon-reload
sudo systemctl enable punchBLE.service

ON-OFF BUTTON

After I finished everything I knew that there was something missing. In fact the RaspberryPI is more like a computer than a MCU and requires safe shutdown and restart this is helpful to avoid any file system corruption.

VA TUTTO [EVERYTHING IS WORKING]

It has been a long process, but I’m pretty happy with the solution I’ve found even if it comes with plenty of trade-offs.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store