User avatar
Autdad44
Posts: 18
Joined: Sun Mar 15, 2015 6:39 pm
Location: South Carolina, USA

Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 12:43 am

I worked through the wired version of the control center project first...everything worked...

Now I am trying to work through setting up the PIR sensor to run through the bluetooth control center set-up...

I am using a HC-06 module on a DuPont cable instead of mounting it to a screwshield as done in the book....

I get my module to pair, connect and trusted to my Pi 3 (also not covered in the book) so I do not have a USB dongle to contend with...

Now, I run 'control.py' for the bluetooth set-up and it gives me this:

Code: Select all

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
    return self.func(*args)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 586, in callit
    func(*args)
  File "/home/pi/zombies/Raspberry_Pi/control_center_bt/control.py", line 88, in update
    app.read_arduino()
  File "/home/pi/zombies/Raspberry_Pi/control_center_bt/control.py", line 51, in read_arduino
    data = volts, temp, door, pir, fire = self.ser.readline().split()
ValueError: need more than 0 values to unpack
I have looked in this forum and several others online...I cannot figure out why it works with the wired version and not the bluetooth....

Please help...this is for my sons homeschool Science curriculum!!!!

User avatar
Autdad44
Posts: 18
Joined: Sun Mar 15, 2015 6:39 pm
Location: South Carolina, USA

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 2:14 am

This is the code from Simon Monk's the Maker's Guide to the Zombie Apocalypse that gives the above error when I run it

Code: Select all

from Tkinter import *
import serial
import time

BAUD = 9600
PORT = "/dev/rfcomm0"

MIN_VOLTS = 11.0
TEMP_MIN = -10.0
TEMP_MAX = 45.0

class App:
    
    def __init__(self, master):

        self.frame = Frame(master)
        self.frame.pack()
        
        Label(self.frame, text='Volts').grid(row=0, column=0, sticky=E)
        self.volts_var = StringVar()
        self.volts_label = Label(self.frame, textvariable=self.volts_var)
        self.volts_label.grid(row=0, column=1)
        
        Label(self.frame, text='Temperature').grid(row=1, column=0, sticky=E)
        self.temp_var = StringVar()
        self.temp_label = Label(self.frame, textvariable=self.temp_var)
        self.temp_label.grid(row=1, column=1)
        
        Label(self.frame, text='Door').grid(row=2, column=0, sticky=E)
        self.door_var = StringVar()
        self.door_label = Label(self.frame, textvariable=self.door_var)
        self.door_label.grid(row=2, column=1)
        
        Label(self.frame, text='PIR').grid(row=3, column=0, sticky=E)
        self.pir_var = StringVar()
        self.pir_label = Label(self.frame, textvariable=self.pir_var)
        self.pir_label.grid(row=3, column=1)
        
        Label(self.frame, text='Fire').grid(row=4, column=0, sticky=E)
        self.fire_var = StringVar()
        self.fire_label = Label(self.frame, textvariable=self.fire_var)
        self.fire_label.grid(row=4, column=1)
        
        self.ser = serial.Serial(PORT, BAUD, timeout=1)
        time.sleep(2)
        


    def read_arduino(self):
        self.ser.write('?')
        data = volts, temp, door, pir, fire = self.ser.readline().split()
        self.volts_var.set(volts)
        self.temp_var.set(temp)
        self.door_var.set(door)
        self.pir_var.set(pir)
        self.fire_var.set(fire)
        if float(volts) < MIN_VOLTS:
            self.volts_label.configure(bg = "red")
        else:
            self.volts_label.configure(bg = "green")
            
        if float(temp) < TEMP_MIN or float(temp) > TEMP_MAX:
            self.temp_label.configure(bg = "red")
        else:
            self.temp_label.configure(bg = "green")
            
        if door == "1":
            self.door_label.configure(bg = "red")
        else:
            self.door_label.configure(bg = "green")
        
        if pir == "1":
            self.pir_label.configure(bg = "red")
        else:
            self.pir_label.configure(bg = "green")
        
        if fire == "1":
            self.fire_label.configure(bg = "red")
        else:
            self.fire_label.configure(bg = "green")        


root = Tk()
root.wm_title('Control')
app = App(root)

def update():
    app.read_arduino()
    root.after(500, update) 

root.after(100, update)


root.mainloop()

User avatar
Douglas6
Posts: 4342
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 3:03 pm

I'm assuming you have the HC-06 connected to an Arduino, and you are using the onboard Bluetooth on the Pi.
1. Have you added the SPP on the Pi?
2. Are you running rfcomm in a different process from your Python script on the Pi?

User avatar
Autdad44
Posts: 18
Joined: Sun Mar 15, 2015 6:39 pm
Location: South Carolina, USA

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 6:34 pm

Douglas6...I have the Arduino set up with a screwshield and a 16,2 LCD shield and I have the PIR sensor and the HC-06 hooked to the screwshield...and I am using the onboard bluetooth on the Pi3..

1) No...I have not....but, just found a post on that..I looked at it and thought it was an application specific thing and didn't realize it pertained to all bluetooth projects even after pairing and connecting was accomplished

2) I don't think so...

User avatar
Douglas6
Posts: 4342
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 6:59 pm

I'm not familiar with that book, but I would think it would mention SPP and rfcomm, since they are required for any Bluetooth serial communications project. It may be that, many years ago, these features were enabled by default (I don't recall), but with newer distributions of Raspbian, they must be configured.

User avatar
Autdad44
Posts: 18
Joined: Sun Mar 15, 2015 6:39 pm
Location: South Carolina, USA

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 7:10 pm

It shows as 'paired, trusted and connected' in bluetoothctl scan, did so before I tried changing the systemd file...so not sure that was my problem...I am just trying to get the gui to show me the readout in bluetooth connection that it did in USB connection...the files are identical except for the 'Port=/dev/rfcomm0' vs /dev/ttyACM0 in the USB control.py file...I went back and redid everything in the USB run and then just changed ports in Arduino IDE and unhooked the USB cable set up the HC-06 and reran it..

I followed your post for the SPP and it still gives me the same error..

User avatar
Douglas6
Posts: 4342
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 7:21 pm

OK, assuming you are paired OK. In a separate terminal window, open bluetoothctl. It should list the Bluetooth device address of your HC-06. If not try the 'paired-devices' command. Copy the device address. Then exit out of bluetoothctl, and enter

Code: Select all

sudo rfcomm connect 0 <bdaddr>
Replace <bdaddr> with the HC-06 device address. What is the result?
Last edited by Douglas6 on Thu Apr 19, 2018 7:23 pm, edited 1 time in total.

User avatar
Autdad44
Posts: 18
Joined: Sun Mar 15, 2015 6:39 pm
Location: South Carolina, USA

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 7:22 pm

in the book to set up the bluetooth version they solder the components onto the screwshield prototyping area whereas I am using one with a Dupont cable connection instead...

In the set up for the USB version he says to use either a Pi B+ or 2....I am using the Pi3...he suggests installing 'bluetooth' 'bluez-utils' {which is just 'bluez' now} and 'bluesman' I did so just to cover myself when the onboard version said there were 'no services for this device' (?)..then I ran 'hciconfig' , then 'hcitool scan', then 'hcitool cc <id num>' and finally, 'rfcomm connect 0 <id num>'

as I said before everything shows as connected, green lights on the bluetooth manager GUI and all...just not sending the info back to the Pi3

User avatar
Douglas6
Posts: 4342
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 7:27 pm

OK, so you ARE running rfcomm. That must continue running in it's own window while your program runs. If the result of the 'rfcomm connect' gives an error, try un-pairing and re-pairing the devices, now that you have SPP running.
Last edited by Douglas6 on Thu Apr 19, 2018 7:31 pm, edited 1 time in total.

User avatar
Autdad44
Posts: 18
Joined: Sun Mar 15, 2015 6:39 pm
Location: South Carolina, USA

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 7:30 pm

CORRECTION: when I run

Code: Select all

sudo rfcomm connect 0 <bdaddr>
I get

Code: Select all

Can't connect RFCOMM socket: Device or resource busy
but if I use

Code: Select all

sudo rfcomm connect hci0 <bdaddr>
it connects fine and returns

Code: Select all

Connected /dev/rfcomm0 to <bdaddr> channel 1
           Press Control+C for hang-up

User avatar
Autdad44
Posts: 18
Joined: Sun Mar 15, 2015 6:39 pm
Location: South Carolina, USA

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 7:32 pm

yes, I leave the connected terminal window open and open another on or just open the file in IDLE2 directly to run the control.py module

User avatar
Douglas6
Posts: 4342
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 7:38 pm

OK, it appears you have successfully connected the two devices. From this point it must be a problem in the code in either the Pi or Arduino sides. Can you add some print statements on the Arduino to see if it receiving data?

User avatar
Autdad44
Posts: 18
Joined: Sun Mar 15, 2015 6:39 pm
Location: South Carolina, USA

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 7:55 pm

This is what I get...I tried the programmer listed "Amtel stk500 dev borad" and others but not luck

Code: Select all

Arduino: 1.8.5 (Linux), Board: "Arduino/Genuino Uno"

Sketch uses 6080 bytes (18%) of program storage space. Maximum is 32256 bytes.
Global variables use 294 bytes (14%) of dynamic memory, leaving 1754 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

User avatar
Douglas6
Posts: 4342
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 8:03 pm

Sorry, I can't be of much help on the Arduino side.

User avatar
Autdad44
Posts: 18
Joined: Sun Mar 15, 2015 6:39 pm
Location: South Carolina, USA

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 8:07 pm

ok....I still don't see how the USB connected contrrol center worked fine, I even changed the Porrt call for the Arduino from /dev/ttyACM0 in that program to /dev/rfcomm0 just to see if there was difference between the Bluetooth version and the USB version...still no good...I think at this point I am going to find a different project resource using the same hardware and see if it helps...maybe with 2 failures or 1 fail/1 pass I will have more data to compare anyway

User avatar
Autdad44
Posts: 18
Joined: Sun Mar 15, 2015 6:39 pm
Location: South Carolina, USA

[SOLVED] Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 9:50 pm

FIXED IT!!!! YAYAAAAAA!!!! TX labeled in the HC-06 board goes to the RX on the screwshield....and RX goes to TX....


User avatar
Autdad44
Posts: 18
Joined: Sun Mar 15, 2015 6:39 pm
Location: South Carolina, USA

Re: Simon Monk's Maker's Guide to the Zombie Apocalypse...problems with bluetooth control center

Thu Apr 19, 2018 10:18 pm

yep...now to try and fix a Cayenne interface so I can send notices to my phone....that's for the end of the whole project though...now that it works my son wants to put a camera with the sensor to activate it...finally, something he's interested in....

Return to “Python”

Who is online

Users browsing this forum: No registered users and 4 guests