ul-gh / PiPyADC

Python classes for interfacing Texas Instruments analog-to-digital converters with the Raspberry Pi
GNU Lesser General Public License v2.1
69 stars 27 forks source link

ADS not initializing... #12

Closed SpacelySpaceSprockets closed 5 years ago

SpacelySpaceSprockets commented 6 years ago

I have a new RPi3 with a new waveshare High-Precision AD/DA board.

I installed your code, but when I run the examples, the board doesn't seem to initialize...I put a couple of print statements in to see where it was making it too..

def do_measurement():
    print('doing measurement\n')
    ### STEP 1: Initialise ADC object:
    ads = ADS1256()
    print('ADS1256 initialized\n')
    ### STEP 2: Gain and offset self-calibration:
    ads.cal_self()
    print('ADS1256 self-calibrated\n')
    while True:
        ### STEP 3: Get data:
        raw_channels = ads.read_sequence(CH_SEQUENCE)
        voltages     = [i * ads.v_per_digit for i in raw_channels]

        ### STEP 4: DONE. Have fun!
        nice_output(raw_channels, voltages)

and it outputs...

PiPyADC: Example file for class ADS1256 in module pipyadc:

ADS1256 cycling through eight input channels.

Hardware: Waveshare ADS1256 board interfaced to the Raspberry Pi 3

Ulrich Lukas 2017-03-10

Press CTRL-C to exit. doing measurement

but nothing else. So Its failing at ads = ADS1256()

Am I forgetting something? It runs with some C code, so I don't think it's a hardware problem.

Thanks

ul-gh commented 6 years ago

Hi,

what is the output if you run:

import wiringpi as wp
wp.wiringPiSetupPhys()

?

SpacelySpaceSprockets commented 6 years ago

0

ul-gh commented 6 years ago

Thanks for your answer - that basically only means that you have the wiringpi libraries installed and this should be working.

What you could do is run the functions from the init function of class ADS1256 (file pipyadc.py) one after the other or debug from this point: https://github.com/ul-gh/PiPyADC/blob/6b314561c47e3cada06c24e0dd35286d6251e6a5/pipyadc.py#L267

I can't help you more than this without further information, I am afraid.

SpacelySpaceSprockets commented 6 years ago

stepping through with pdb I get this

/home/pi/PiPyADC/pipyadc.py(329)init() -> self.reset() (Pdb) --Call-- /home/pi/PiPyADC/pipyadc.py(525)reset() -> def reset(self): (Pdb) /home/pi/PiPyADC/pipyadc.py(529)reset() -> self._chip_select() (Pdb) --Call-- /home/pi/PiPyADC/pipyadc.py(343)_chip_select() -> def _chip_select(self): (Pdb) /home/pi/PiPyADC/pipyadc.py(346)_chip_select() -> if self.CS_PIN is not None: (Pdb) /home/pi/PiPyADC/pipyadc.py(347)_chip_select() -> wp.digitalWrite(self.CS_PIN, wp.LOW) (Pdb) --Return-- /home/pi/PiPyADC/pipyadc.py(347)_chip_select()->None -> wp.digitalWrite(self.CS_PIN, wp.LOW) (Pdb) /home/pi/PiPyADC/pipyadc.py(530)reset() -> self._send_byte(CMD_RESET) (Pdb) --Call-- /home/pi/PiPyADC/pipyadc.py(358)_send_byte() -> def _send_byte(self, mybyte): (Pdb) /home/pi/PiPyADC/pipyadc.py(365)_send_byte() -> wp.wiringPiSPIDataRW(self.SPI_CHANNEL, "%s" % chr(mybyte&0xFF))

Program crashes on the last line... values are...

/home/pi/PiPyADC/pipyadc.py(367)_send_byte() -> wp.wiringPiSPIDataRW(self.SPI_CHANNEL, "%s" % chr(mybyte&0xFF)) (Pdb) pp self.SPI_CHANNEL 1 (Pdb) pp mybyte&0xFF 254 (Pdb)

chr(254) = '\xfe'

ul-gh commented 6 years ago

Hi, not sure, (I've had the second beer for today, it's past midnight here and I also don't have access to the hardware) but this could be a WiringPi issue. You can try out the PiGPIO branch if you want: https://github.com/ul-gh/PiPyADC/tree/pigpio. If you want, I can look into this later, but today - not a chance.. Best wishes, Ulrich

SpacelySpaceSprockets commented 6 years ago

we can take this up again tomorrow. Enjoy the beer

SpacelySpaceSprockets commented 6 years ago

Yep, it worked with the pigpio branch

ul-gh commented 5 years ago

This could be related to the Python 3 issue #18, which is fixed via the latest commits. If there are still problems, please reopen this issue.