Introduction
Hi! This update will be focused on the theme of this whole competition, bluetooth. The first idea was connecting 2 Raspberries via bluetooth, but I had a lot of trouble with doing that the way I wanted to, and in the end ended up needing to reset one of the Pi's completely due to the power supply issue. So I will go with my second option which is making a custom bluetooth powered Arduino controller which will communicate with the Raspberry.
First Bluetooth Test
This is my first contact with bluetooth on Raspberry so I thought why not go and try out a simple project. I got new blinds installed in my room 2 weeks ago or so, and due to the lack of space, a manual tape couldn't be installed, so it could only have the motor inside (not complaining at all!!!). So my first thought was, how can I easily control this using my phone? Of course that led to using bluetooth. There is no need for any circuitry, only one double relay module, or two single relay modules. Conveniently, on the Google Play Store I found "Pi3 Bluetooth Manager", which turned out to work great. I followed the instructions on how to connect and all it did was write out the data sent from a phone, so I just took the value sent, and if the value is 1 or 2, i either raised or lowered the blinds for 10 seconds. I didn't dig any deeper into this, but will in the future for sure, so I can program it to exact positions! Here is a video of the blinds working.
Connecting the Arduino and Raspberry
The hero board - Raspberry Pi 3 model B+, has integrated bluetooth, but the Arduino does not. For the test now I will be using an Arduino Uno, but will later transfer all of it to either an Arduino Pro Micro, or an Arduino Nano, which will come in a later blog.
Arduino
Let's start off with the Arduino, as I've said I'll be using the uno for this test. To connect it to the Raspberry using bluetooth we need a bluetooth module of some sorts. There are loads of them to choose from, I went with the HC-05. I used it in a project a few years back so I thought why not use it again. I found online a lot of different ways to wire up this part, but in the end I found this one working good for me.
Now the only thing left is to code it. The code is really short and simple since this is just a test. All I wanted to do with this test is establish communication between the Raspberry and Arduino, so the code just sends messages to the Raspberry via bluetooth, while in the upcoming blogs, I will update the Arduino code to read some button presses as well as some other things.
#include <SoftwareSerial.h> SoftwareSerial mySerial(10, 11); // RX, TX void setup() { Serial.begin(9600); Serial.println("Monitor:"); mySerial.begin(9600); mySerial.println("Hello"); } void loop() { if(mySerial.available()) Serial.write(mySerial.read()); if(Serial.available()) mySerial.write(Serial.read()); }
That is all on the Arduino side for now, time to jump over to the Raspberry.
Raspberry Pi
Now we come to the hero board. There are 2 things that we need to do, first off we need to connect the Raspberry and the HC-05, and the second thing is we need to read data from the HC-05. Let's start off by connecting them.
Connecting to the HC-05
Here is a step by step guide on connecting to the HC-05:
{gallery} HC-05 |
---|
That would be all that's needed for connecting to the bluetooth module. We firstly pair it through the drop down menu on the Pi, some modules require a password while others don't, if they do, it's usually 1234 or 0000, after that with hcitool scan we find the address of the bluetooth module, and with sudo rfcomm connect hci0 98:D3:31:20:8F:FA 1 we connect the module to channel 1. Next thing and last thing we need to do is write a code that grabs data.
Reading Data
I've tried a few different things here but the only one that worked almost instantly without a lot of troubleshooting was this method. We firstly need a small code which will fetch data.
#! /usr/bin/python import serial bluetoothSerial = serial.Serial("/dev/rfcomm0",baudrate=9600) print("Waiting for data:") try: while 1: data = bluetoothSerial.readline() print(data) except KeyboardInterrupt: print("Quit")
And that would be all that's needed to connect the Arduino and Raspberry over bluetooth, I'll be using this combo for now, but would love to upgrade it to Raspberry Raspberry, since that would enable me to have an active screen at all times which could even stream video, but this work great as well! The response time on the Raspberry is great which will provide a nice gamepad experience later on. Here is a video showcasing the bluetooth communication.
First Communication Test
Summary
This is a small but crucial step in the build, since everything else will for the most part rely on this. There's not much time left so it's time to kick it into an upper gear! For the next blog I will be making an Arduino based gamepad which will be used to communicate with the Raspberry. Thank you for reading, hope you liked it!
Milos
Top Comments