Today’s community project is our first project targeting Arduino shield boards. The CY8CKit-042 Pioneer Kit is hardware compatible with numerous Arduino shield boards. In the coming weeks we will showcase various shield boards that are available to Arduino users.
Today’s example project uses the “Danger Shield” which includes a list of hardware features such as three large sliding potentiometers, LEDs, LDR light sensor, push buttons, buzzer, and a small 7 segment LED display. The example and descriptions are included in this post.
This example project uses the LEDs, LDR light sensor, a switch and our USB-UART bridge to report debug data to the PC. The project demonstrations the use of the LDR light sensor on the Danger shield, integrates the digital switch to run a calibration routine and then uses the LED outputs to indicate the light intensity measured (high or low). The UART interface communicates the status and debug messages across the USB-UART bridge available on the PSoC 4 Pioneer Kit.
The user can download the example project at the bottom of this post. The project uses the following list of Creator Components:
- ADC SAR (LDR sensor)
- UART (Debugging)
- Debouncer (Clean up switch signal)
- Status Register (Button State)
- CyPins (LEDs)
(PSoC Creator Schematic)
The components are configured by right clicking on the component in your Top Design schematic view and selecting Configure. Please enable the following selections in the Configuration windows for the listed components above.
(Configure menu for ADC SAR)
(Configure menu for UART)
(Configure menu for Debouncer)
The main.c firmware is included in the example project. Please review the commented sections for more details. The code first initializes a number of project variables and arrays. Once the user enters into the main loop a number of variables and arrays are initialized and the components are started. The code then enters into two separate calibration routines. These routines cover both the Low and High light calibration of the light sensor. The calibrations are controlled and initiated by the digital button presses by the user. Once the calibration is complete the UART initializes the debug messaging and then enters into the main loop. In the application loop the ADC is measuring the LDR sensor output and then calculating whether or not a threshold has been met. Depending on the LDR sensor value the application will toggle between two LEDs.
For this example project the user will need to connect one piece of hardware and connect two wires. First the user will need to connect the two wires to the J8 header from the PSoC 5LP. Please refer to the USB-UART example project (#04) for images. Connect the wire to the PSoC 5LP P12  (on J8) and a second wire to P12  (on J8).
You will then need to connect the Danger Shield to the PSoC 4 Pioneer Kit. Once the shield board is connected then take the two wires and connect them to the headers on the Shield board. Connect the wires to the following PSoC 4 pins on the shield board header.
PSoC 4 UART RX P0 --> PSoC 5LP P12  (on J8)
PSoC 4 UART TX P0 --> PSoC 5LP P12  (on J8)
In the previous example we connected the UART pins to the header of the Pioneer Kit. Since we have the Shield board connected to the Pioneer kit in this example we needed to connect the UART wires to the header on the Shield board.
Test Your Project:
Once programmed with this project, your PSoC 4 Pioneer Kit is setup to begin the example.
Next launch a serial interface tool like PuTTy. We dicussed this in example #04 when we were discussing the USB-UART functionality. Once your PuTTy settings are enabled click open to launch the serial window.
First press the reset button on the Pioneer kit to ensure the example project starts from the beginning.
After resetting you will need to press the D12 digital button. The LED will toggle during the calibration. Press the D12 digital button again and the calibration will be complete. Then wave your hand over the LDR sensor and you will see the LED's toggle between D6 and D5.
Next view the PuTTy output window. The example will continuously output data to the PuTTy window. You will see the data change as you wave your hand over the LDR sensor.
I hope this example can help you out in your design.
DangerShield-LDR Sensor.zip 233.8 KB