Recent

Author Topic: How to read a resistor value with RPI?  (Read 5358 times)

Ramses

  • New Member
  • *
  • Posts: 41
How to read a resistor value with RPI?
« on: February 04, 2021, 06:28:06 pm »
Hi!

I'm using a raspberry, and want to read the value of a resistor (like a ohmmeter).

Does its possible to read the value of a resistor connected between two pin of my raspberry with lazarus?
 
If yes can you give me an exemple of code to do that? If its not possible, which external hardware does i need to read my resistor value easily with lazarus?

Thanks!

MarkMLl

  • Hero Member
  • *****
  • Posts: 8525
Re: How to read a resistor value with RPI?
« Reply #1 on: February 04, 2021, 06:51:38 pm »
I'm really not sure that circuit design lies within the remit of this forum.

You basically have two possibilities: either put a constant current through the resistor and read the voltage across it using an ADC, or set up the unknown resistor with a known high-precision resistor as a potential divider and read the voltage at the common point.

However with both of these you'll find that since your ADC resolution (note: resolution, not precision) is limited, you wouldn't be able to read more than a few of the standard values (E12, E24 etc.) before you had to tell the current source to change its range or would have to change the known resistor in your potential divider.

At this point you really need to think about what you're doing, since as a general solution you'd do better finding something like a general-purpose multimeter that you could interrogate over a (simulated) serial interface, or some specialised measurement module from any of the usual suspects.

HTH, but this might not be the appropriate place to discuss this.

MarkMLl

p.s. the brand is "Raspberry Pi", not "Raspberry".
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to read a resistor value with RPI?
« Reply #2 on: February 04, 2021, 07:11:02 pm »
p.s. the brand is "Raspberry Pi", not "Raspberry".
Nitpicking and totally O.T. but, wouldn't you better say the brand is "Raspberry" and the product family "Pi", with models 1, 2, 3, etc.? :)

Though you're right in the sense that "a Raspberry" might be either a Pi [computer/microcontroller], an IQAudio, a Pi camera, etc. 
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8525
Re: How to read a resistor value with RPI?
« Reply #3 on: February 04, 2021, 07:25:19 pm »
p.s. the brand is "Raspberry Pi", not "Raspberry".
Nitpicking and totally O.T. but, wouldn't you better say the brand is "Raspberry" and the product family "Pi", with models 1, 2, 3, etc.? :)

Though you're right in the sense that "a Raspberry" might be either a Pi [computer/microcontroller], an IQAudio, a Pi camera, etc.

:-) Probably not, since I believe that the trading name is "The Raspberry Pi Foundation".

In any event, I'm currently struggling to resist the temptation to look for rock-bottom measurement devices controlled by a serial port (possibly simulated using USB), I2C or whatever. Hopefully I've given OP enough Google fodder that he'll be able to work out why he'll have range problems etc.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Ramses

  • New Member
  • *
  • Posts: 41
Re: How to read a resistor value with RPI?
« Reply #4 on: February 04, 2021, 07:29:15 pm »
You basically have two possibilities: either put a constant current through the resistor and read the voltage across it using an ADC, or set up the unknown resistor with a known high-precision resistor as a potential divider and read the voltage at the common point.

Alright, so according to what i read, its not possible to do it directly with my "raspberry pi 3 b+" and i need to use an analog to digital converter..

Thanks for your answer, so i will order an ADC first, then when the ADC is received i will try to read my resistor value from it using lasarus..

« Last Edit: February 04, 2021, 07:30:53 pm by Ramses »

MarkMLl

  • Hero Member
  • *****
  • Posts: 8525
Re: How to read a resistor value with RPI?
« Reply #5 on: February 04, 2021, 08:25:56 pm »
Alright, so according to what i read, its not possible to do it directly with my "raspberry pi 3 b+" and i need to use an analog to digital converter..

Thanks for your answer, so i will order an ADC first, then when the ADC is received i will try to read my resistor value from it using lasarus..

I was assuming there was something integrated, but a quick Google suggests I was wrong.

Frankly, if you're having to buy an ADC you'd be better off- IMO- looking for some sort of measurement module with some sort of range control. Most ADCs will have something like 12-bit precision, i.e. 4096 steps... now let's say you set it up so that full-scale (i.e. a reading of $0fff) is 40 kOhms your minimum reading will be 10 Ohms and that's a very small part of the range of values for which standard resistors are easily available (0.1 Ohm to 100 MOhm would be realistic, which is 10^9 i.e. roughly 30 bits).

Alternatively you need to firm your ideas up and decide what range of resistor you need to measure.

MarkMLl

p.s. Item 333847772291 on eBay is a cheap multimeter with USB capability. It's probably good to better than 5% which is about what I'd expect a beginner to get if he were designing and building his own hardware, but I've absolutely no idea how easy it would be to interface to it. HTH, but that really is about all I can do.
« Last Edit: February 04, 2021, 08:31:52 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

dseligo

  • Hero Member
  • *****
  • Posts: 1651
Re: How to read a resistor value with RPI?
« Reply #6 on: February 04, 2021, 08:58:26 pm »
Alternatively you need to firm your ideas up and decide what range of resistor you need to measure.
Maybe he wants to measure some NTC thermistor or some LDR and he doesn't need very wide range, so 12 bit or even 10 bit ADC will be enough for him.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8525
Re: How to read a resistor value with RPI?
« Reply #7 on: February 04, 2021, 09:06:20 pm »
Alternatively you need to firm your ideas up and decide what range of resistor you need to measure.
Maybe he wants to measure some NTC thermistor or some LDR and he doesn't need very wide range, so 12 bit or even 10 bit ADC will be enough for him.

Yes, maybe. But as things stand he's asked a very general question and the best we can do is give him a general answer, some Googling terms, and tell him what he needs to improve if he wants more specific advice.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Ramses

  • New Member
  • *
  • Posts: 41
Re: How to read a resistor value with RPI?
« Reply #8 on: February 05, 2021, 01:50:43 am »
Maybe he wants to measure some NTC thermistor or some LDR and he doesn't need very wide range, so 12 bit or even 10 bit ADC will be enough for him.

Thanks for all your reply.

in fact, here is exactly why i wanna read the ohm value: i have few differents external device that i want to connect to my project (let say for exemple: 10 differents speaker), i want my "raspberry pi 3 b+" to be able to detect which speaker is connected, so i decided to use 4 wire to each speaker: wires 1 and 2 for audio, and wires 3 and 4 that have a resistor between them (it could be any value i want). 

exemple:
 speaker 1 have audio signal on wire 1 - 2 and have 10k resistor between wire no3 and 4
 speaker 2 have audio signal on wire 1 - 2 and have 20k resistor between wire no3 and 4
 speaker 3 have audio signal on wire 1 - 2 and have 30k resistor between wire no3 and 4
etc....

That way, if each speaker have a different resistor value, my "raspberry pi 3 b+" will "see" that the first one is connected if they read 10kohm for exemple, then if they read 20kohm "raspberry pi 3 b+" will know that the second speaker is connected, etc...

So, for sure i dont need i very large range of detection, as long as i can read 10 different resistor (of any value) thats ok for me...

ojz0r

  • Jr. Member
  • **
  • Posts: 72
Re: How to read a resistor value with RPI?
« Reply #9 on: February 05, 2021, 07:22:28 am »
Then you want an ADC with a voltage divider. Posible ADC would be MCP3208 (12-bit resolution) or even a MCP3008 (10-bit). Since precision isnt a factor you can chose the cheapest. Dont have the resistors to close to each other in value since the resistans changes with temperature.
The easiest way to communicate with the ADC is with SPI or I2C.
I like big endians and i can not lie.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8525
Re: How to read a resistor value with RPI?
« Reply #10 on: February 05, 2021, 10:01:36 am »
So, for sure i dont need i very large range of detection, as long as i can read 10 different resistor (of any value) thats ok for me...

That's the important thing. So if you set up a potential divider with the fixed resistor being 47k (note: that's a "preferred value", see https://en.wikipedia.org/wiki/E12_series) you'd get roughly 50% of the rail voltage if your unknown were also 47k decreasing roughly in proportion with the value of your unknown.

/However/, if all you're trying to do is do a 1-of-4 identification it would be easier if you assumed that one end of your speaker was grounded, at which point you could have two sense wires which were either grounded or left floating in a binary pattern. That would take 2x GPIO pins set to input with pullup resistors, leaving your I2C available for other use.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

ccrause

  • Hero Member
  • *****
  • Posts: 1088
Re: How to read a resistor value with RPI?
« Reply #11 on: February 05, 2021, 11:55:57 am »
Other analog options that should be relatively cheap to build:
Use 555 timer in single shot mode, can use this to measure either unknown capacitance against known resistor value, or vice versa.  Trigger 555, measure pulse width of output, resistor value is proportional to RC, so knowing the measurement capacitor, the unknown resistor value can be calculated.

Or (dis)charge a cap through unknown resistor.  Send voltage through comparator to generate a signal at fixed reference voltage (or rely on the build-in threshold of the digital pins, but I expect that to be somewhat variable)  Again, resistance can be calculated from RC (dis)charge curve.

Just in case the OP is interested in applying some analog domain solution...

kupferstecher

  • Hero Member
  • *****
  • Posts: 604
Re: How to read a resistor value with RPI?
« Reply #12 on: February 05, 2021, 11:59:26 am »
Does its possible to read the value of a resistor connected between two pin of my raspberry with lazarus?

For your intended usecase, I think its not time critical, so you could use two port pins to measure the load time of a capacitor. See schematic below. Portpin2 is the measurement input, Portpin1 starts with level low to discharge the capacitor. Then you change Portpin1 to High, the capacitor gets charged. You poll the input value of Portpin2 to measure the time between the moment you changed Portpin1 to high and the moment the input value of Portpin2 changes to high. This time is your analog value, the smaller R1 the faster C1 is loaded, the shorter your measured time. Make sure that C1 is really empty when you start the measurement.

Code: Text  [Select][+][-]
  1.  Portpin1 o---------------------
  2.                                |
  3.                               ---
  4.                              |   |
  5.                              |   |  R1
  6.                              |   |
  7.                               ---
  8.                                |
  9.  Portpin2 o---------------------
  10.                                |
  11.                              =====  C1
  12.                              =====
  13.                                |
  14.                                |
  15.                               ===
  16.                               GND
  17.  

Edit: ccrause was faster...

dseligo

  • Hero Member
  • *****
  • Posts: 1651
Re: How to read a resistor value with RPI?
« Reply #13 on: February 05, 2021, 12:45:45 pm »
MarkMLI suggestion is good, but if you need more than 4 speakers you'd need more wires.
ccrause's and kupferstecher's solutions are fine, but are a bit complicated because they involve measuring time and calculations.

You could make resistor network (R-2R) and a comparator (e.g. LM324 wired as a comparator). It would need 4 output GPIO's and one input GPIO for 16 different values.

You'd go from 0 to 15 on output GPIO's and check input GPIO when comparator flip.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8525
Re: How to read a resistor value with RPI?
« Reply #14 on: February 05, 2021, 12:59:02 pm »
MarkMLI suggestion is good, but if you need more than 4 speakers you'd need more wires.
ccrause's and kupferstecher's solutions are fine, but are a bit complicated because they involve measuring time and calculations.

You could make resistor network (R-2R) and a comparator (e.g. LM324 wired as a comparator). It would need 4 output GPIO's and one input GPIO for 16 different values.

You'd go from 0 to 15 on output GPIO's and check input GPIO when comparator flip.

I think we all need to bear in mind that- with respect- OP's electronics experience is limited, and we don't know what testgear he's got. I for one would be very reluctant to get involved with debugging something as complex as a 555 oscillator remotely... I've tried to throw in terms that he should be able to interpret using Wikipaedia etc. but I think that's about as much as can be reasonably done.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018