ADC Pi and GUI Help - Raspberry Pi Forums


hi im python beginner , trying small gui program made work adc pi add on board, ive ran example code http://elinux.org/rpi_adc_i2c_python , works in command line, ive gone through glade tutorials , got basic gui , running getting them working stumping me, following error when trying display output value:

code: select all

traceback (most recent call last):   file "./adc_demo.py", line 88, in on_sfm_button_clicked     self.rpm = (getadcreading(adc_address1, adc_channel1))   file "./adc_demo.py", line 40, in getadcreading     bus.transaction(i2c.writing_bytes(address, channel))   file "/home/pi/quick2wire-python-api/src/quick2wire/i2c.py", line 72, in transaction     ioctl(self.fd, i2c_rdwr, addressof(ioctl_arg)) ioerror: [errno 25] inappropriate ioctl device 
python code im running is:

code: select all

#!/usr/bin/env python3 # read abelectronics adc pi board inputs # uses quick2wire http://quick2wire.com/ # github: https://github.com/quick2wire/quick2wire-python-api # requries python 3  # i2c api depends on i2c support in kernel # # modified version of example code on http://www.abelectronics.co.uk/products/3/raspberry-pi/7/adc-pi---raspberry-pi-analogue-to-digital-converter # see http://elinux.org/rpi_adc_i2c_python full setup instructions  import quick2wire.i2c i2c gi.repository import gtk import re import time  adc_address1 = 0x68 adc_address2 = 0x69  adc_channel1 = 0x98 adc_channel2 = 0xb8 adc_channel3 = 0xd8 adc_channel4 = 0xf8   line in open('/proc/cpuinfo').readlines():     m = re.match('(.*?)\s*:\s*(.*)', line)     if m:         (name, value) = (m.group(1), m.group(2))         if name == "revision":             if value [-4:] in ('0002', '0003'):                 i2c_bus = 0             else:                 i2c_bus = 1             break  i2c.i2cmaster(i2c_bus) bus:      def getadcreading(address, channel):         bus.transaction(i2c.writing_bytes(address, channel))         time.sleep(0.05)         h, l, r = bus.transaction(i2c.reading(address,3))[0]         time.sleep(0.05)         h, l, r = bus.transaction(i2c.reading(address,3))[0]          t = (h << 8) | l         v = t * 0.000154         if v < 5.5:             return v         else: # must floating input             return 0.00  class buglump:    def __init__(self):     self.gladefile = "tutorial-4.glade"     self.builder = gtk.builder()     self.builder.add_from_file(self.gladefile)     self.builder.connect_signals(self)     self.window = self.builder.get_object("window1")     self.aboutdialog = self.builder.get_object("aboutdialog1")     self.statusbar = self.builder.get_object("statusbar1")     self.window.show()    def on_window1_destroy(self, object, data=none):     print ("quit cancel")     gtk.main_quit()    def on_gtk_quit_activate(self, menuitem, data=none):     print ("quit menu")     gtk.main_quit()    def on_push_status_activate(self, menuitem, data=none):     print ("updated status bar")     self.message_id = self.statusbar.push(0, "updated status bar")    def on_pop_status_activate(self, menuitem, data=none):     print ("cleared status bar")     self.statusbar.remove_message(0, self.message_id)    def on_gtk_about_activate(self, menuitem, data=none):     print ("help selected")     self.response = self.aboutdialog.run()     self.aboutdialog.hide()    def on_sfm_button_clicked(self, button, data=none):     self.result1 = self.builder.get_object("result1")     self.rpm = getadcreading(adc_address1, adc_channel1)     print ("calculate rpm clicked")     self.result1.set_text(self.rpm)  if __name__ == "__main__":   main = buglump()   gtk.main()
can point me in direction of ive gone wrong? in advance.

first things first

1/ if run i2cdetetect terminal window device seen

2/ have tried simple console style programme in python first setup adc , grab 1 reading
display result , configuration codes.

cannot see have defined quickwire calls correctly or have right sequence talking device.

have no idea adc chip using if have wired correctly, if pi can see device on i2c bus, let alone if code right.


raspberrypi



Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums