2

So I'm doing a project today with the Raspberry Pi 2 Model B and I realized that some (not all) of the GPIO pins output 3.3V at startup (I mean the data pins, not the power output pins). I cannot have it output 3.3V since I'm using the RPI to control a quadcopter and that would cause a mess if the motors ran at full speed at bootup. So do you guys know which pins are 0V (off) at startup and I can control using WiringPi?

Peter Zhu
  • 268
  • 3
  • 12
  • We would know if we read the datasheet. You too. –  Nov 10 '15 at 22:16
  • I never worked with RPI, but, in general, MCU GPIOs start in high impedance mode. You can try a pull down resistor (10k-100k) for each motor control GPIOs. –  Nov 10 '15 at 22:18
  • @EugeneSh. I cant seem to find any datasheets for the RPI. If you find it can you please link me to it? – Peter Zhu Nov 10 '15 at 22:20
  • everything is [here](https://www.raspberrypi.org/documentation/hardware/raspberrypi/README.md). Start with the board schematic as it may contain pull ups/downs and other stuff on the GPIOs, and then look at the processor docs GPIO section –  Nov 10 '15 at 22:23
  • They may start in High-Z, but may go high or low somewhere in the Linux boot sequence. Many pins have multiple functions, and some may not even be gpio, just gpo – cde Nov 10 '15 at 22:56
  • You can not guarantee the GPIO settings will be fixed between power-up and the time your software gets control. All sorts of other software may intervene and change the settings (unless you are prepared to lock down the software and do no more kernel/package updates). You MUST use a hardware solution if you want to guarantee safety. – joan Nov 10 '15 at 22:58
  • A pi directly controlling the motors of a quadcopter doesn't sound like a good design at all. If you want to use a pi for mission-level tasks such as navigation or decisioning that might make sense on paper (though still not in practice, as it isn't reliable, and isn't friendly to battery power) but it really does not belong in the flight stabilization role - dedicate a simpler MCU with fewer failure modes to that. – Chris Stratton Nov 11 '15 at 00:22

2 Answers2

2

All the GPIO pins start as inputs (except the 2 used for serial console), so they may appear "high" if read with a voltmeter, but you could easily override this.

gpio readall will show state.

I believe you can change the startup state (you could search just as easily as I). In the brief period before the config is read they must be indeterminate. You need some other method if you wish to manage state.

Milliways
  • 54,718
  • 26
  • 92
  • 182
  • If the pins are input (High-Z), the processor may have weak pull-ups automatically enabled to avoid problems with floating inputs. You can probably make them look low on startup by putting a 4.7K (or even 10K) ohm pull-down resistor to ground on each. This should easily overcome the internal weak pull-up but not interfere with using the pin as an output. – DoxyLover Nov 10 '15 at 23:10
  • So how do I use gpio readall? – Peter Zhu Nov 10 '15 at 23:15
  • @DoxyLover the GPIO does not work like this. It is years since I read the data sheets, so this may not be exactly correct, but the GPIO has an internal state e.g. if it has been used as an output, and set low, when switched to input it still reports a low value. `gpio readall` will show many pins as 0, even with nothing connected. – Milliways Nov 10 '15 at 23:18
  • @peterzhu2118 type `gpio readall` on the command line. – Milliways Nov 10 '15 at 23:19
  • @Milliways So I got that working, I understand all the columns except the "V" column. What is the supposed to mean? – Peter Zhu Nov 10 '15 at 23:25
  • @Milliways I just found out that the "V" column is for values. So I have either a 1 or a 0 value for that column. What does that mean? – Peter Zhu Nov 10 '15 at 23:29
  • @Milliways my comment doesn't refer to how the pin reads internally but to how it acts electrically; that a pin set for input probably has an internal weak pull up which is easily overridden with a pull-down to prevent an **external** device from reading the (temporary) input pin as high. – DoxyLover Nov 11 '15 at 01:06
  • @DoxyLover Interesting theory. Have you read the data sheet (or better tried reading the voltage). – Milliways Nov 11 '15 at 05:45
  • I have no experience with the RPi, I followed the migration from Electronics Stackexchange. This comes from my experience with other microprocessors and microcontrollers. That's why I said "may have" and "probably". – DoxyLover Nov 11 '15 at 06:57
2

I just got I2C and WiringPi installed a few hours ago. To expand on what @Milliways said, I rebooted and checked the output of gpio readall. See the attached image. It appears most all the pins start as inputs.

gpio readall output on RPi B board

user38537
  • 203
  • 1
  • 5