Riding a bike is a great low-carbon mode of transportation and way to get exercise, but for people who do not live in cycling-friendly cities, the effort can quickly turn dangerous. Every year in the US, thousands are struck by cars and nearly one thousand are killed. This project aims to alleviate the problem by providing early warnings that a car is approaching and improved signals for turning.
The core of the project is the CY8CPROTO-062-4343W PSoC 6 WiFi and Bluetooth prototyping kit from Infineon which uses a PSoC 62 microcontroller with 2MB of flash storage and 1MB of SRAM. Also onboard is the Cypress CYW4343W combo wireless module for fast and easy communication. Users are able to swipe and press on the built-in CAPSENSE module while the code detects which gesture is present through the CAPSENSE library.
Early warnings of approaching vehicles are generated by the S2GO BGT60LTR11 radar module as it allows for targets up to seven meters away to be detected. A pair of red LEDs can be mounted to the end of each handlebar and function as the turn signals and brake lights for other drivers to easily notice. Finally, power is delivered via a SparkFun LiPo Charger Plus module and LiPo battery cell.
All of the code is written in C using ModusToolbox libraries, HALs, and board support packages (BSPs). The radar module can optionally be used with SPI, but I opted for the digital pin interface only. With the mode selection switch (QS1
) set to the left on the S2GO module, it runs in autonomous mode and does not require SPI communication. The range potentiometer (R_QS2
) was set to maximum.
Set up as its own FreeRTOS task, the radar_task
starts by calling a simple library I created for the BGT60 that takes in two digital pins as inputs: one for TD
(Target Detection) and one for PD
(Phase or direction Detection). It then checks if TD is set, and if it is, will check if the direction is approaching or departing. The results are both stored in the passed-in struct and returned.
In order for the user to input that they want to turn, the capsense_task
from the BLE Capsense example was repurposed to include CAPSENSE gestures. It works by continuously reading the five slider pins and, when combined with a timestamp, will determine the gesture. I used the CAPSENSE Configuration tool within the ModusToolbox IDE to perform the setup. Currently, a one-finger flick left or right is required to signal left or right, but slides and perhaps more complex gestures could be included in the future.
After the correct gesture has been detected, the data is sent from the capsense_task
to a corresponding indicator_task
whose sole purpose is to handle the signaling LEDs and control how they blink based on the current direction.
Although not present in this version of the project, the BLE capabilities of the CY8CPROTO-062-4343W would allow it to communicate with an accompanying smartphone app and allow the user to perform many actions and see approaching vehicles. Because of this, the code has a ble_task
that accepts messages from other tasks to update two services and their child characteristics: Radar.Detection
and TurnSignal.Status
. They each have a Client Characteristic Configuration for sending notifications when they update, and TurnSignal.Status
even supports writes for send indication commands from a phone.
Holding the CAPSENSE board in-place against the handlebars is a custom 3D printed enclosure that has cutouts for the two capacitive buttons on either side and the central slider.
Comments