I’m having trouble with my ADC0834 setup on a Raspberry Pi 5 which I purchased from core electronics. I’m using bookworm and despite following a guide, my setup only returns zeros. Here are the details:
Connections:
CLK on the chip connected to pin 18
CS on the chip connected to pin 17
DI (which I believe is bidirectional as per the guide) connected to pin 27
Middle leg of my potentiometer connected to CH0 on the chip
All VCC and GND for the potentiometers are connected
Hi Matthe
The red wire is not connected to anything. It is not very clear but I think that black square thing is the pot. Is that supposed to be the pot centre connection. At the moment is plugged into a breadboard strip that does not seem to connect to anything.
Cheers Bob
Hi Bob!
Yes, the red wire isn’t connected to the potentiometer. I think I must have gotten mixed up, as before, I had the potentiometer over the trench. I’ll fix it up soon, and get back to you with the results. Thanks!
I think it may be just about ALL of the problem.
After all you would not expect to get anything but zero with nothing connected to the analog ADC input.
Cheers Bob
Part or all, it’s an issue, though in projects of my own, many a time I have fixed one issue only to find 3 more that rear their heads. I would never jinx myself by saying it fixes the whole issue, that’s surely a direct challenge to the law of maximum inconvenience.
It sure is. But surely common sense would suggest the first thing to do is make sure some volts are getting to the analog input. Zero volte equates to 0 ADC output.
Have there been any voltage measurements ??? It does not sound like it as there has been no mention of anything like this.
Cheers Bob
Hi Matthew
As I just replied above. What sort of voltage can you measure at the ADC analog input.
An DC output of 0 possibly indicates zero input volts.
Cheers Bob
PS:
The fact that it is reporting SOMETHING could mean the ADC itself is probably OK. Not too sure what happens actually here as I have never used an off board ADC myself. Always came with the other bits.
I tested the output to the DI pin of the chip by disconnecting the connection between my GPIO and DI, then reconnecting a wire from the GPIO that was previously controlling the DI to a new GPIO. I used a quick line of code to read and print the value being outputted after each GPIO controlling DI output. Additionally, I found an issue with my code’s setup and corrected it. I’ve updated the original post. Here is my code:
import time
import gpiod
freq = 50_000
one_cycle = 1/freq
half_cycle = one_cycle/2
val = 0
chip = gpiod.Chip('gpiochip0')
CS = chip.get_line(17)
DIO = chip.get_line(27)
CLK = chip.get_line(18)
test=chip.get_line(21)
CS.request(consumer='dev1', type=gpiod.LINE_REQ_DIR_OUT)
CLK.request(consumer='dev2', type=gpiod.LINE_REQ_DIR_OUT)
DIO.request(consumer='dev3', type=gpiod.LINE_REQ_DIR_OUT)
test.request(consumer='dev4', type=gpiod.LINE_REQ_DIR_IN)
try:
CS.set_value(0)
CLK.set_value(0)
CLK.set_value(0)
time.sleep(half_cycle)
DIO.set_value(1)
CLK.set_value(1)
time.sleep(half_cycle)
val = test.get_value()
print(val)
CLK.set_value(0)
time.sleep(half_cycle)
DIO.set_value(1)
CLK.set_value(1)
time.sleep(half_cycle)
val = test.get_value()
print(val)
CLK.set_value(0)
time.sleep(half_cycle)
DIO.set_value(0)
CLK.set_value(1)
time.sleep(half_cycle)
val = test.get_value()
print(val)
CLK.set_value(0)
time.sleep(half_cycle)
DIO.set_value(0)
CLK.set_value(1)
time.sleep(half_cycle)
val = test.get_value()
print(val)
CLK.set_value(0)
time.sleep(half_cycle)
DIO.set_value(0)
DIO.release()
DIO = chip.get_line(27)
DIO.request(consumer='dev3', type=gpiod.LINE_REQ_DIR_IN)
for i in range(8):
bit = DIO.get_value()
print(bit)
CLK.set_value(1)
time.sleep(half_cycle)
CLK.set_value(0)
time.sleep(half_cycle)
time.sleep(2)
CS.set_value(1)
except KeyboardInterrupt:
CS.release()
CLK.release()
DIO.release()
The results came back as expected, with the first two being ones and the second two being zeros.
Additionally, I’m not using the DO pin on the chip to get data. The guide I’m following suggests switching the DI pin from output to input via the Pi. Do you think this could be an issue, and should I check the DO pin instead? Any more ideas on why it is malfuncti
Hi Matthew
That is all pretty much Swahili to me. Don’t know much at all about RPi.
I asked if you had measured any voltage at the ADC analog input. How you check the input level by swapping D0, D1 and GPIO is beyond me and you better believe I have done a lot of trouble shooting over the last 40 or 50 years. I am assuming here that D0 and D1 are ADC0 and ADC1 data outputs of the ADC chip and a GPIO is reading the ADC outputs from those pins. I have not looked at the Data sheet for that chip as at the moment I have no real reason to do that.
I ask again. Have you measured any voltage at the DC input pin. Measure this right on the pin in case you have a dodgy breadboard. Set the pot to about half way. If you don’t see any voltage you will have to chase back and find out where it disappears.
That is about the first thing you should have done. If the ADC does not see any input voltage you will get 0 output.
Hi Bob,
I’ve just got one question regarding how the CLK signal works. In my code, the CLK signal is not very stable and has chunks of code in between. Isn’t a typical clock signal meant to be very stable and precise? Does it matter how much time is in between each signal? Additionally, is there any way I can know when to place different clock signals in my code?
Thanks, Matthew.
I would have thought so.
I just had a look at the data sheet for the chip. D1 (or DI) seems to be an input or I suppose could be output. CLK is an input and D0 (or DO) is a data output. It is a bit hard to ascertain if it is D! or DI (D uppercase i) or in D0 is it numeral 0 or uppercase o.
When you say you appear to have data mixed with clock you have not got the connections reversed have you. It seems to be a common problem. Try it, I don’t think you can hurt anything.
I don’t know anything much about how all this is decoded and I have not got time to start now. I thought there were breakout boards around to do this ADC job which did all the smart things and provided I2C or SPI or something output. If I were doing this that is he way I would have to go as I don’t know enough to get down to chip level.
I also don’t know enough about RPi coding th know if the ADC decoding is happening in your sketch or wherever.
If you are interested in going down this path Core have a selection. Some look like they plug straight onto a RPi with a 40 pin header on board.
Cheers Bob