A few posts ago I posted about the bluetooth and the PSoC and was asked to post some code for it. So here it is some sample code to write from Android via Bluetooth to the PSoC. This is nothing close to what my project be but it is a test of the different components and others might found it useful so why not share it.
Hardware
PSoC Pioneer Kit
Bluetooth to Serial TTL adapter (cheap adapter close to $10 ebay/amazon .... )
Software
PWM
UART
Android application (https://github.com/soynerdito/AndroidPSoCBluetooth)
Overview
I copied the PWM from the PSoC capacitance sample. Then added an UART control with 9600 baud rate. Wrote a simple Android app to send a character via Bluetooth.
The bluetooth device is called "linvor" with passcode 1234. If you use a different one, may need to change the code to use the one you needed. Before using the app the bluetooth device should be paired with the phone (the same way you pair a headset) with it's corresponding pin code. The app will try to connect to an already paired device named linvor, please note that this is a simple sample code without any error checking. Original code gotten from the android developer site sample and modified a little bit.
On the PSoC when receiving a character (integer value) I did the exact same thing as the demo (shift the bits) and write to the PWM control. I control the range of the values like the example, from 1 to 127 (I skipped the 0).
It is pretty straight forward. On the demo the PWM is written when an interrupt is generated, here is when a character from 1 to 127 arrives.
Testing the app with the PSoC



-
DAB
-
Cancel
-
Vote Up
0
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
-
camuyano
in reply to DAB
-
Cancel
-
Vote Up
0
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
Comment-
camuyano
in reply to DAB
-
Cancel
-
Vote Up
0
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
Children