Somewhere in the gawdawful mess that is my "lab" is a basic R'Pints rig using an Uno with Bluetooth...
View attachment 371781
Ah, there it is!
View attachment 371782
Note the Uno - and the detached USB cable and the BT radio laying on edge.
Pours are registering perfectly over the BT link.
There's also a PIR and some BrewPi stuff wired up to the RPi2B and working as well.
So, here's the How To Do's
Using an UNO instead of an AlaMode for R'Pints
- You can follow the RaspberryPints "With Flow Meters" installation and completely skip Step 6 where AlaMode-specific stuff is installed. It's not needed.
Perform Steps 7 and 8, then in Step 9, skip the AlaMode assembly and use the instructions on how to configure the Arduino sketch for the number of meters and the meter pin assignments.
You'll configure these lines of the sketch file located at /var/www/arduino/raspberrypints.ino
Code:
//This line is the number of flow sensors connected.
const uint8_t numSensors = 4;
//This line initializes an array with the pins connected to the flow sensors
uint8_t pulsePin[] = {8,9,10,11};
DO NOT SAVE THE SKETCH YET!
- Next, change the baud rate setting in the sketch from 9600 to 57600 as shown:
Code:
void setup() {
pinMode(13, OUTPUT);
// initialize serial communications at 57600 bps:
Serial.begin(57600);
The Uno USB/serial bridge defaults to 57.6K baud and there's no good reason not to use that speed.
NOW save the sketch.
- Next, edit the R'Pints Python listener /var/www/python/flow_monitor.py
Disable the 'port' command line for /dev/ttyS0, enable the 'port' command line that points to /dev/ttyACM0, and change the baud rate to 57600 (I modified the original so the options are listed):
Code:
#The following line is for serial over GPIO
#port = '/dev/ttyS0'
#The following line is for serial over USB
port = '/dev/ttyACM0'
#The next line is for serial over GPIO
#arduino = serial.Serial(port,9600,timeout=2)
#The next line is for serial over USB
arduino = serial.Serial(port,57600,timeout=2)
- Next, plug the Uno into the host RPi via a USB cable and run the Arduino IDE.
o In Tools/Board select Arduino UNO (should be the top of the list)
o In Tools/Serial Port select /dev/ttyACM0
o In File/Open select the sketch at /var/www/arduino/raspberrypints.ino
o Click the Right Arrow button to compile and upload the sketch to the Uno.
- Finally, start the flowmon service:
Code:
$ sudo /etc/init.d/flowmon start
- Check to verify the service is running:
Code:
$ sudo /etc/init.d/flowmon status
pi@cpints:~ $ sudo /etc/init.d/flowmon status
● flowmon.service - LSB: Put a short description of the service here
Loaded: loaded (/etc/init.d/flowmon)
Active: active (running) since Wed 2016-09-28 21:10:38 EDT; 46min ago
.
.
.
- Hook up a flow meter and give it a try.
Note that using a USB link instead of the AlaMode shield opens the road to using something other than an Uno.
The sketch is so tiny and uses so few elements I'd be surprised if you couldn't use pretty much any Arduino available with enough digital IO pins to suit the number of taps needed...
Using an Uno with Bluetooth for R'Pints
This section assumes one already has an Uno running with R'Pints (see above
)
Assuming one has built-in BT or a BT USB dongle plugged into their RPi (or other host), and a BT/serial bridge (eg: HC-05, HC-06) plugged into an Uno, I'll show what needs to be done to get them to play together.
Note: the basics of using an HC-05 or HC-06 with an Uno can be found
here. You can find the simple connectivity including a highly-recommended resistor level-shifter on the Uno serial TX signal to the HC-0x serial RX input to keep from blowing up the latter.
So, assuming one has an HC-05 or HC-06 properly wired to an Uno TX, RX, 5V and GND pins, here's what needs to be done:
- in a terminal session, find the MAC address of the BT/serial bridge:
Code:
$ hcitool scan
Scanning ...
00:02:72:32:D8:2C OBELISK
98:D3:31:80:25:64 BPSAT_3
OBELISK is my workstation's BT radio, the other entry is an HC-05 BT/serial module.
Note I believe it's included with standard Jessie distros, but if you don't have hcitool installed:
$ sudo apt-get update
$ sudo apt-get install hcitool
- next, on the desktop, go to Menu - Preferences, find the Bluetooth Manager, right-click on it and "Add to desktop".
- now launch the Bluetooth Manager
o click the Search button to scan for BT devices
o click on the entry for the BT bridge (HC-05 or -06)
The correct entry will have the MAC address listed as found above.
o click the plus sign icon to add this device to the "known" list
o click the keg icon to add this device to the "trusted" list.
o click the Setup... button to get into the connection dialog
o you'll need to Pair the device using the key (likely 1234) and then Connect the device.
o once successfully added you can close the dialog pane.
- next, back at the command line, use
rfcomm to bind the BT/serial bridge channel 1 to virtual port rfcomm0 (assumes this is the first bridge - if you already have any rfcomm ports, use the first free port number)
Code:
$ sudo rfcomm bind 0 98:D3:31:80:25:64 1
- Then check the status:
Code:
$ rfcomm show rfcomm0
rfcomm0: 98:D3:31:80:25:64 channel 1 clean
- If you get that far, edit /home/pi/.config/lxsession/LXDE-pi/autostart and add the same
rfcomm bind command to the end of that file.
- next, change the listener port used by the flow monitor process to rfcomm0 (or whatever port you've created) by editing the Python file /var/www/python/flow_monitor.py.
Note I've added two more lines vs what I showed in the "Use an Uno" section, the better to illustrate all the options now available.
Code:
#The following line is for serial over GPIO
#port = '/dev/ttyS0'
#The following line is for serial over USB
#port = '/dev/ttyACM0'
#The following line is for serial over Bluetooth:
port = '/dev/rfcomm0'
Reboot the system and verify the BT module is connected and pour data is being conveyed successfully...
Cheers!