7

I bought the "Sunfounder Sensor Kit" for Raspberry Pi 2, but the whole content is made for Arduino (5V). I have bought ADC, Level Shifters but I am stuck because I think I certainly miss a simple solution.

  1. I read that voltage divider with resistors would not work correctly before an ADC. EDIT: http://electronics.stackexchange.com
  2. My ADC has a SPI interface, so I need a bi-directional exchange with Pi, but if I power it with 5V, I need a level Shifter for GPIO. I have only mono-directional level shifters.

I don't know how to use these sensors efficiently ?

  • Could I use one level shifter in each direction on the same ADC between it and GPIOs ?

  • Do I need bi-directional level shifter ?

  • Do you know a 5V->3.3V ADC ?

Did I miss a simple solution ? Thank you.

  • 1
    I'm not sure where you read that voltage divider wouldn't work. May you can post a link. It's indeed a simple yet elegant solution. Here : build-electronic-circuits.com/wp-content/uploads/2013/08/… Where, Vin is your input signal and vout is your output signal. Keep R1 and R2 as per your need. For example, to have a 3.3v signal when your input is 5v, you will need to have R1 = 100k ohms and R2 = 200k ohms roughly and likewise. Hope it helps. – dhruvvyas90 Jun 29 '15 at 15:05
  • 2
    As dastaan suggest use a voltage divider on MISO (from ADC to the Pi to cut the output from 5V to 3V3). You can then power the ADC from 5V and use that as the reference voltage. All the other ADC SPI signals (MOSI, SCLK, SS) are inputs from the Pi. The ADC will still work even if the signals are 3V3. – joan Jun 29 '15 at 15:10
  • 1
    Have you tried running the sensor at 3.3V? Many of the analog (and quite a few digital) sensors for Arduino can actually run 3-5.5V just fine. Popular sensors that work like this that come to mind are TMP036 (temperature), water level sensors, and flex sensors. – Nathan Jun 29 '15 at 16:04
  • The link I talked about is here : http://electronics.stackexchange.com. It seems there is a problem with the impedance for ADC. – Elo Jun 30 '15 at 7:16
  • @joan : thanks a lot for the explanation of the only pin to translate from 5V to 3.3V ! – Elo Jun 30 '15 at 7:35
7

For the analog sensors such as the photoresister and the hall effect sensor (and most likely others as suggested in the comments), you can supply them with 3.3V and still have them work correctly.

They should act as a simple variable resistance in the presence of an external influence. Hopefully the following image will illustrate for a photoresister;

Photoresister

(just to clarify, in the case of the sensor kit you're using, the 10k Ohm resister that forms part of the divider below is already incorporated into the sensor board) The analog output is then fed into the ADC.

The ADC I have used for this type of connection is the Adafruit ADS1015. It will run from 3.3V quite happily.

This is how you would have them connected;

enter image description here

The connection of analog inputs to the Pi (in exactly this way) is the topic of the next chapter in 'Raspberry Pi: Measure, Record, Explore' and should be available in a couple of days time. EDIT: The chapter is now published and the book is available for free from Leanpub here.

  • Hobby Hall effect sensors are typically open collector digital outputs, not analogue. Open collector digital outputs can typically be connected directly to the Pi. – joan Jun 29 '15 at 19:10
  • @joan : The kit includes multiple versions. Sunfounder Sensor Kit. In black "analogy hall sensor" and "hall sensor" (switch type as they say I think), and a third one, in red "Linear-hall sensor", with 4 pins, which I believe does analog and digital (4 pins). – Elo Jun 30 '15 at 7:29
  • @Elo Fair enough, I've not come accross those yet. The digital ones are used in simple pulse counters such as fluid flow sensors, motherboard fan tachometers, and some weather wind vanes. – joan Jun 30 '15 at 7:32
  • This is certainly only applicable for the analog sensors (and I'm assuming that they will be materially the same as the Keyes versions). But they work simply enough. – d3noob Jun 30 '15 at 9:48
  • 1
    Thanks, your comment and ebook helped me connect the ADS1115 to my sensor and R Pi 3. – Tia Jan 11 '18 at 21:37
0

Perhaps you could use PCF8591 which is analog to digital converter. It does more then simple binary check, it does convert voltage to digital value. It is configurable. It takes 2.5 to 6 volts for power. You could set some not-so-frequent update for the device and scan it's output for value greater then what you would expect.

  • Thank you for your proposal. Inputs max voltage is Vdd+0.5 Datasheet. So if I power it with 5V, outputs would be 5V too. So we come back to @joan proposal. – Elo Jul 1 '15 at 10:25
  • @Elo, not exactly, since it uses I2C as output. So output can be 3.3V, digital. You have to power it with at least 5V, because it can read up to Vdd + 0.5V on input. – Piotr Kamoda Jul 1 '15 at 10:52
0

You can also use a bi-directional level shifter - I bought a two-line (3.3 <==> 5.0 Volts) one from a retailer on a popular on-line action site - which explicitly mentioned it's I2C compatibility (some do, some say nothing - which is why I choose the former) for a couple of GB Pounds. (I didn't get any indication which of the "A" and "B" labelled lines were for which voltage, but the UK based retailer quickly furnished me with that data on request!) That goes into the SDA and SCL lines and to the two (5.0 & 3.3) Supply rails with the ground (0V) being common to BOTH sides. The "external" I2C signals are now 5V based and they, and the 5V supply can be extended to other 5V-powered devices using that bus without danger of causing harm to the Pi.

EDIT: I was looking at d3noob's answer rather than the OP's question, that was using the I2C bus but the OP's referred to SPI. Whilst the details are different, the cost involved of using an actual converter designed to the job for one of those buses is more than made up by the protection that they give to the vulnerable GPIO pins on the Pi.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.