Legal Removal Request This form is for reporting content posted on the AB Electronics UK forums that you believe violates your personal legal rights or applicable local laws for your country. Post: Hello Andrew and thank you very much for your prompt reply. I have been experiencing strange limitations when trying to copy code from Nano and pasting into the code snippet window on the forum (both on my RPi and my Ubuntu distribution on my PC). It seems to only allow a small amount to be copied - even when setting a mark with Alt>Shift>A and scrolling to highlight all the text. I tried copying with keystrokes and the mouse but to no avail. Interestingly, this problem also occurs when pasting into a text file or any other type of file / window - which leads me to believe maybe the limitation is in the copying rather than the pasting. However, I have had success opening the .py script with leafpad and copy / paste from there - so here is the code I was trying to attach yesterday. This code below only reads / logs from the first 4 channels of the first ADC board & it works nicely: ________________________________________________________________________________________________ [pre][code]#!/usr/bin/env python3 # read abelectronics ADC Pi V2 board inputs with repeating reading from each channel. # uses quick2wire from http://quick2wire.com/ github: https://github.com/quick2wire/quick2wire-python-api # Requries Python 3 # GPIO API depends on Quick2Wire GPIO Admin. To install Quick2Wire GPIO Admin, follow instructions at http://github.com/quick2wire/quick2wire-gpio-admin # I2C API depends on I2C support in the kernel # #------------------------------------------------------------------------------ import quick2wire.i2c as i2c import time import datetime #------------------------------------------------------------------------------ adc_address_1 = 0x6A adc_address_2 = 0x6B adc_address_3 = 0x6C adc_address_4 = 0x6D refresh_rate = 3 # seconds log_ratio = 4 # logs every log_ratio cycles varDivisior = 64 # from pdf sheet on adc addresses and config varMultiplier = (1.0000/varDivisior)/1000 adcmonLog = "/home/pi/DATALOG/P4139-11.log" #------------------------------------------------------------------------------ def writeLog(channel1mv, channel2mv, channel3mv, channel4mv): try: log = open(adcmonLog, "a") currentdatetime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M') log.write(currentdatetime) log.write(",Channel_1_(mV)=%.0f" % channel1mv) log.write(",Channel_2_(mV)=%.0f" % channel2mv) log.write(",Channel_3_(mV)=%.0f" % channel3mv) log.write(",Channel_4_(mV)=%.0f" % channel4mv) log.write("\n") except: pass #------------------------------------------------------------------------------ logCountDown = 1 with i2c.I2CMaster() as bus: # Usage: changechannel(address, hexvalue) # to change to new channel on adc chips def changechannel(address, adcConfig): bus.transaction(i2c.writing_bytes(address, adcConfig)) # Usage: getadcreading(address) to return value in volts from # selected channel. def getadcreading(address): h, m, l ,s = bus.transaction(i2c.reading(address,4))[0] while (s & 128): h, m, l, s = bus.transaction(i2c.reading(address,4))[0] # shift bits to product result t = ((h & 0b00000001) << 16) | (m << 8) | l # check if positive or negative number and invert if needed if (h > 128): t = ~(0x020000 - t) return t * varMultiplier while True: # read first 4 channels and convert to millivolts changechannel(adc_address_1, 0x9C) channel1mv = 1000 * getadcreading(adc_address_1) changechannel(adc_address_1, 0xBC) channel2mv = 1000 * getadcreading(adc_address_1) changechannel(adc_address_1, 0xDC) channel3mv = 1000 * getadcreading(adc_address_1) changechannel(adc_address_1, 0xFC) channel4mv = 1000 * getadcreading(adc_address_1) # Log logCountDown -= 1 if (logCountDown == 0): writeLog(channel1mv, channel2mv, channel3mv, channel4mv) logCountDown = log_ratio time.sleep(refresh_rate) [/code][/pre] _________________________________________________________________________________________________ So then I modified it to what I believed would work, and this is the modified script below - intended to read 16 channels. (As mentioned earlier - I can see the presence of the 4 addresses when I query i2cdetect -y 1), so am satisfied the hardware is recognised). This code appears to be a bit messy in terms of text alignment - but it appears fine in Nano and Leafpad. _________________________________________________________________________________________________ [pre][code]#!/usr/bin/env python3 # read abelectronics ADC Pi V2 board inputs with repeating reading from each channel. # uses quick2wire from http://quick2wire.com/ github: https://github.com/quick2wire/quick2wire-python-api # Requries Python 3 # GPIO API depends on Quick2Wire GPIO Admin. To install Quick2Wire GPIO Admin, follow instructions at http://github.com/quick2wire/quick2wire-gpio-admin # I2C API depends on I2C support in the kernel # #------------------------------------------------------------------------------ import quick2wire.i2c as i2c import time import datetime #------------------------------------------------------------------------------ adc_address_1 = 0x6A adc_address_2 = 0x6B adc_address_3 = 0x6C adc_address_4 = 0x6D refresh_rate = 3 # seconds log_ratio = 4 # logs every log_ratio cycles varDivisior = 64 # from pdf sheet on adc addresses and config varMultiplier = (1.0000/varDivisior)/1000 adcmonLog = "/home/pi/DATALOG/P4139-11.log" #------------------------------------------------------------------------------ def writeLog(channel1mv, channel2mv, channel3mv, channel4mv, channel5mv, channel6mv, channel7mv, channel8mv, channel9mv, channel10mv, channel11mv, channel12mv, channel13mv, channel14mv, channel15mv, channel16mv): try: log = open(adcmonLog, "a") currentdatetime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M') log.write(currentdatetime) log.write(",Channel_1_(mV)=%.0f" % channel1mv) log.write(",Channel_2_(mV)=%.0f" % channel2mv) log.write(",Channel_3_(mV)=%.0f" % channel3mv) log.write(",Channel_4_(mV)=%.0f" % channel4mv) log.write(",Channel_5_(mV)=%.0f" % channel5mv) log.write(",Channel_6_(mV)=%.0f" % channel6mv) log.write(",Channel_7_(mV)=%.0f" % channel7mv) log.write(",Channel_8_(mV)=%.0f" % channel8mv) log.write(",Channel_9_(mV)=%.0f" % channel9mv) log.write(",Channel_10_(mV)=%.0f" % channel10mv) log.write(",Channel_11_(mV)=%.0f" % channel11mv) log.write(",Channel_12_(mV)=%.0f" % channel12mv) log.write(",Channel_13_(mV)=%.0f" % channel13mv) log.write(",Channel_14_(mV)=%.0f" % channel14mv) log.write(",Channel_15_(mV)=%.0f" % channel15mv) log.write(",Channel_16_(mV)=%.0f" % channel16mv) log.write("\n") except: pass #------------------------------------------------------------------------------ logCountDown = 1 with i2c.I2CMaster() as bus: # Usage: changechannel(address, hexvalue) # to change to new channel on adc chips def changechannel(address, adcConfig): bus.transaction(i2c.writing_bytes(address, adcConfig)) # Usage: getadcreading(address) to return value in volts from # selected channel. def getadcreading(address): h, m, l ,s = bus.transaction(i2c.reading(address,4))[0] while (s & 128): h, m, l, s = bus.transaction(i2c.reading(address,4))[0] # shift bits to product result t = ((h & 0b00000001) << 16) | (m << 8) | l # check if positive or negative number and invert if needed if (h > 128): t = ~(0x020000 - t) return t * varMultiplier while True: # read first 16 channels and convert to millivolts changechannel(adc_address_1, 0x9C) channel1mv = 1000 * getadcreading(adc_address_1) changechannel(adc_address_1, 0xBC) channel2mv = 1000 * getadcreading(adc_address_1) changechannel(adc_address_1, 0xDC) channel3mv = 1000 * getadcreading(adc_address_1) changechannel(adc_address_1, 0xFC) channel4mv = 1000 * getadcreading(adc_address_1) changechannel(adc_address_2, 0x9C) channel5mv = 1000 * getadcreading(adc_address_2) changechannel(adc_address_2, 0xBC) channel6mv = 1000 * getadcreading(adc_address_2) changechannel(adc_address_2, 0xDC) channel7mv = 1000 * getadcreading(adc_address_2) changechannel(adc_address_2, 0xFC) channel8mv = 1000 * getadcreading(adc_address_2) changechannel(adc_address_3, 0x9C) channel9mv = 1000 * getadcreading(adc_address_3) changechannel(adc_address_3, 0xBC) channel10mv = 1000 * getadcreading(adc_address_3) changechannel(adc_address_3, 0xDC) channel11mv = 1000 * getadcreading(adc_address_3) changechannel(adc_address_3, 0xFC) channel12mv = 1000 * getadcreading(adc_address_3) changechannel(adc_address_4, 0x9C) channel13mv = 1000 * getadcreading(adc_address_4) changechannel(adc_address_4, 0xBC) channel14mv = 1000 * getadcreading(adc_address_4) changechannel(adc_address_4, 0xDC) channel15mv = 1000 * getadcreading(adc_address_4) changechannel(adc_address_4, 0xFC) channel16mv = 1000 * getadcreading(adc_address_4) # Log logCountDown -= 1 if (logCountDown == 0): writeLog(channel1mv, channel2mv, channel3mv, channel4mv, channel5mv, channel6mv, channel7mv, channel8mv, channel9mv, channel10mv, channel11mv, channel12mv, channel13mv, channel14mv, channel15mv, channel16mv) logCountDown = log_ratio time.sleep(refresh_rate) [/code][/pre] I couldn't immediately see where the original code had a reference like that which you provided yesterday: [pre][code] adc1 = ADCPi(0x68, 0x69, 12) adc2 = ADCPi(0x6A, 0x6B, 12)[/code][/pre] I could only see these references to addresses (which seemed to work fine on the first script reading only 4 channels - but not for the script to read 16 channels) [pre][code]adc_address_1 = 0x6A adc_address_2 = 0x6B adc_address_3 = 0x6C adc_address_4 = 0x6D[/code][/pre] I feel I am getting closer to the solution, but being very new to all this, I am probably missing something very simple! Any assistance would be greatly appreciated! ChrisH Select the country where you are claiming legal rights. Albania Algeria American Samoa Andorra Angola Anguilla Antarctica Antigua and Barbuda Argentina Aruba Australia Austria Bahamas Bahrain Bangladesh Barbados Belarus Belgium Belize Benin Bermuda Bhutan Bolivia Bosnia And Herzegovina Botswana Bouvet Island Brazil British Indian Ocean Territory British Virgin Islands Brunei Bulgaria Burkina Faso Burundi Cambodia Cameroon Canada Canary Islands Cape Verde Cayman Islands Central African Republic Chad Channel Islands Chile Christmas Island Cocos (Keeling) Islands Colombia Comoros Congo Cook Islands Costa Rica Croatia Cuba Cyprus Czech Republic Denmark Djibouti Dominica Dominican Republic East Timor Ecuador Egypt El Salvador Equatorial Guinea Estonia Ethiopia Falkland Islands (Malvinas) Faroe Islands Federated States of Micronesia Fiji Finland France French Guiana French Polynesia French Southern Territories Gabon Gambia Georgia Germany Ghana Gibraltar Greece Greenland Grenada Guadeloupe Guam Guatemala Guyana Haiti Heard Island and McDonald Islands Honduras Hong Kong Hungary Iceland India Indonesia Ireland Israel Italy Jamaica Japan Jordan Kazakhstan Kenya Kiribati Kuwait Kyrgyzstan Laos Latvia Lesotho Liechtenstein Lithuania Luxembourg Macau Macedonia Madagascar Malawi Malaysia Maldives Mali Malta Marshall Islands Martinique Mauritania Mauritius Mayotte Mexico Micronesia, Federated States Of Moldova, Republic Of Monaco Mongolia Montenegro Montserrat Morocco Mozambique Myanmar Namibia Nauru Nepal Netherlands Netherlands Antilles New Caledonia New Zealand Nicaragua Niue Norfolk Island Northern Mariana Islands Norway Oman Palau Panama Papua New Guinea Paraguay Peru Philippines Pitcairn Poland Portugal Puerto Rico Qatar Reunion Romania Russia Rwanda Samoa San Marino Sao Tome and Principe Saudi Arabia Serbia Seychelles Singapore Slovakia Slovenia Solomon Islands South Africa South Georgia and the South Sandwich Islands South Korea Spain Sri Lanka St. Helena St. Kitts and Nevis St. Lucia St. Pierre and Miquelon St. Vincent and the Grenadines Suriname Svalbard and Jan Mayen Islands Swaziland Sweden Switzerland Syria Taiwan Tajikistan Tanzania Thailand Togo Tokelau Tonga Trinidad and Tobago Tunisia Turkey Turkmenistan Turks and Caicos Islands Tuvalu U.S. Virgin Islands Uganda Ukraine United Arab Emirates United Kingdom United States United States Minor Outlying Islands Uruguay Uzbekistan Vanuatu Vatican City Venezuela Vietnam Wallis and Futuna Islands Western Sahara Yemen Yugoslavia Zambia What legal issue or problem do you wish to report? Please select Privacy / Erasure under GDPR Defamation Intellectual Property Hate Speech Other Please enter the following information so we can process your report. Contact Name: Contact Email: Details of complaint: Submit Complaint