|
Edited by shaggy63 at 2018-5-14 21:25
I'm running h3droid on a orangepi pc in my car. I have the orangepi pc plugged into a anker ravpower power pack which is then plugged into my car for power. There's plenty of information on how to shut off the orangepi safely but nothing about turning it back on.
I used a arduino nano hooked to a relay which grounds pin PC04 when power is high on the power pack and ungrounds it when power is low. The relay is also connected to the fan on the oragepipc so when the orangepi is on the fan is also on. I wrote a script that checks the PC04 pin on the orangepi and runs h3fakeoff when it's no longer grounded. Thanks everyone at h3droid for the help and awesome work.
This script is placed in /data/rc.local (Create it if it doesn't exist)
- #!/system/bin/sh
- /system/bin/sunxi-pio -m PC04'<0><default><default><default>'
- x=1
- while [ $x -le 1 ]
- do
- y=`sunxi-pio -m PC04 | tr -d '<' | tr -d '>' | tr -d '\n' |tr -d ' '`
- z=PC40111
- if [ $z == $y ]
- then
- sleep 30
- /system/bin/reboot -p
- fi
- sleep 30
- done
Copy code Arduino nano code, once programmed plug the arduino into a orangepi usb port.
- #define relay A1 // Connect to A1 pin, Ground and +5 on arduino. Connect relay switch to orangepi PC04 and Ground.
- #define interval 10000 // 10 seconds
- int carpower;
- int pistatus;
- int powerlvl;
- int lowpower=4000;
- int highpower=4600;
- void setup()
- {
- pinMode(relay, OUTPUT);
- Serial.begin(9600);
- digitalWrite(relay, HIGH);
- }
- void loop()
- {
- powerlvl = readVcc();
- if (powerlvl < lowpower)
- {
- Serial.print("Power is low Shutting down = ");
- Serial.println(lowpower);
- delay(60000); // one minute?
- digitalWrite(relay, LOW); // Power off
- }
- if (powerlvl >= highpower)
- {
- if (pistatus == 0)
- {
- Serial.println("Turning on CarPC");
- digitalWrite(relay, HIGH); // Turn the power to relay on
- }
- Serial.print("pistatus is = ");
- Serial.println(pistatus);
- Serial.print("carpower is = ");
- Serial.println(carpower);
- }
- Serial.print("Battery Power = ");
- Serial.println(powerlvl);
- delay(interval);
- }
- long readVcc() {
- // Read 1.1V reference against AVcc
- // set the reference to Vcc and the measurement to the internal 1.1V reference
- #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
- ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
- #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
- ADMUX = _BV(MUX5) | _BV(MUX0);
- #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
- ADMUX = _BV(MUX3) | _BV(MUX2);
- #else
- ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
- #endif
- delay(2); // Wait for Vref to settle
- ADCSRA |= _BV(ADSC); // Start conversion
- while (bit_is_set(ADCSRA,ADSC)); // measuring
- uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
- uint8_t high = ADCH; // unlocks both
- long result = (high<<8) | low;
- result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
- return result; // Vcc in millivolts
- }
Copy code
I'll post my h3fakeof when I can, this is from memory.
- #Workaround for h3droid h3fakeoff
- mount -o rw,remount /system
- mv /system/bin/h3fakeoff /system/bin/h3fakeoff.old
- cp /system/bin/h3fakeoff.sh /system/bin/h3fakeoff
- modify the /system/bin/h3fakeoff to call h3fakeoff.old with -b PC04
Copy code
#todo Add temp monitor, add timer to shutdown after an hour of power off so it doesn't completely drain the power pack.
|
|