please choosego to mobile | Continue to access the PC version
View: 6884|Reply: 6

Carputer - Automatic boot/shutdown

[Copy link]

1

threads

2

posts

19

credits

Novice

Rank: 1

credits
19
Published in 2018-5-14 21:21:28 | Show all floors |Read mode
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)
  1. #!/system/bin/sh
  2. /system/bin/sunxi-pio -m PC04'<0><default><default><default>'
  3. x=1
  4. while [ $x -le 1 ]
  5. do
  6. y=`sunxi-pio -m PC04 | tr -d '<' | tr -d '>' | tr -d '\n' |tr -d ' '`
  7. z=PC40111
  8. if [ $z == $y ]
  9. then
  10. sleep 30
  11.         /system/bin/reboot -p
  12. fi
  13. sleep 30
  14. done
Copy code
Arduino nano code, once programmed plug the arduino into a orangepi usb port.
  1. #define relay A1 // Connect to A1 pin, Ground and +5 on arduino.  Connect relay switch to orangepi PC04 and Ground.
  2. #define interval 10000 // 10 seconds
  3. int carpower;
  4. int pistatus;
  5. int powerlvl;
  6. int lowpower=4000;
  7. int highpower=4600;
  8. void setup()
  9. {
  10. pinMode(relay, OUTPUT);
  11. Serial.begin(9600);
  12. digitalWrite(relay, HIGH);
  13. }

  14. void loop()
  15. {
  16.   powerlvl = readVcc();
  17.   if (powerlvl < lowpower)
  18. {   
  19.   Serial.print("Power is low Shutting down = ");
  20.   Serial.println(lowpower);
  21.   delay(60000); // one minute?
  22.   digitalWrite(relay, LOW); // Power off
  23.   }
  24.   if (powerlvl >= highpower)
  25.   {
  26.     if (pistatus == 0)
  27.     {
  28.       Serial.println("Turning on CarPC");
  29.       digitalWrite(relay, HIGH); // Turn the power to relay on
  30.     }
  31.     Serial.print("pistatus is = ");
  32.     Serial.println(pistatus);
  33.     Serial.print("carpower is = ");
  34.     Serial.println(carpower);
  35.   }
  36.   Serial.print("Battery Power = ");
  37.   Serial.println(powerlvl);
  38.   delay(interval);
  39. }

  40. long readVcc() {
  41.   // Read 1.1V reference against AVcc
  42.   // set the reference to Vcc and the measurement to the internal 1.1V reference
  43.   #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  44.     ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  45.   #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
  46.     ADMUX = _BV(MUX5) | _BV(MUX0);
  47.   #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
  48.     ADMUX = _BV(MUX3) | _BV(MUX2);
  49.   #else
  50.     ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  51.   #endif  

  52.   delay(2); // Wait for Vref to settle
  53.   ADCSRA |= _BV(ADSC); // Start conversion
  54.   while (bit_is_set(ADCSRA,ADSC)); // measuring

  55.   uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
  56.   uint8_t high = ADCH; // unlocks both

  57.   long result = (high<<8) | low;

  58.   result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
  59.   return result; // Vcc in millivolts
  60. }
Copy code

I'll post my h3fakeof when I can, this is from memory.

  1. #Workaround for h3droid h3fakeoff
  2. mount -o rw,remount /system
  3. mv /system/bin/h3fakeoff /system/bin/h3fakeoff.old
  4. cp /system/bin/h3fakeoff.sh /system/bin/h3fakeoff
  5. 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.


1

threads

2

posts

19

credits

Novice

Rank: 1

credits
19
 Author| Published in 2018-5-16 02:14:03 | Show all floors
Fixed some variables.
  1. #define relay A1
  2. #define interval 1000 // 10 seconds
  3. int pistatus;
  4. int powerlvl;
  5. int lowpower;
  6. int highpower;
  7. void setup()
  8. {
  9. pinMode(relay, OUTPUT);
  10. Serial.begin(9600);
  11. digitalWrite(relay, HIGH);
  12. lowpower=4000;  //Test your battery and see what the dead voltage is * 1000
  13. highpower=4600;  // Test your battery and see what it reads once charging power is applied
  14. delay(2000);
  15. powerlvl = readVcc();
  16. pistatus = 1;

  17. }

  18. void loop()
  19. {
  20.   powerlvl = readVcc();

  21.   if (powerlvl < lowpower)
  22. {   
  23.   //Lets check again
  24.   delay(10000);
  25.   powerlvl = readVcc();
  26.   if (powerlvl < lowpower)
  27. {
  28.   Serial.print("Power is low Shutting down = ");
  29.   Serial.println(lowpower);
  30.   delay(60000); // one minute?
  31.   digitalWrite(relay, LOW); // Power off
  32.   
  33.   pistatus = 0;
  34.   }
  35. }
  36.   if (powerlvl >= highpower)
  37.   {
  38.     if (pistatus == 0)
  39.     {
  40.       Serial.println("Turning on CarPC");
  41.       digitalWrite(relay, HIGH); // Turn the power to relay on
  42.       pistatus = 1;
  43.     }
  44.     Serial.print("pistatus is = ");
  45.     Serial.println(pistatus);
  46.   }
  47.   Serial.print("Battery Power = ");
  48.   Serial.println(powerlvl);
  49.   delay(interval);
  50. }

  51. long readVcc() {
  52.   // Read 1.1V reference against AVcc
  53.   // set the reference to Vcc and the measurement to the internal 1.1V reference
  54.   #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  55.     ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  56.   #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
  57.     ADMUX = _BV(MUX5) | _BV(MUX0);
  58.   #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
  59.     ADMUX = _BV(MUX3) | _BV(MUX2);
  60.   #else
  61.     ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  62.   #endif  

  63.   delay(2); // Wait for Vref to settle
  64.   ADCSRA |= _BV(ADSC); // Start conversion
  65.   while (bit_is_set(ADCSRA,ADSC)); // measuring

  66.   uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
  67.   uint8_t high = ADCH; // unlocks both

  68.   long result = (high<<8) | low;

  69.   result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
  70.   return result; // Vcc in millivolts
  71. }
Copy code

0

threads

112

posts

322

credits

Intermediate member

Rank: 3Rank: 3

credits
322
Published in 2022-3-9 00:25:53 | Show all floors
Fabulous article. That blog post impinges on a whole lot of immediate need conflicts of the contemporary culture. You cannot be uninvolved to help you a lot of these conflicts. It blog post grants ideas and even creative concepts. Highly insightful and even helpful.        Packers and Movers Mumbai to Chandigarh

0

threads

112

posts

322

credits

Intermediate member

Rank: 3Rank: 3

credits
322
Published in 2022-3-24 02:46:00 | Show all floors
There are several internet websites pertaining to travel arrangements, lodges and vehicle accommodations comparison yet not just one that enables and also households and also travelers to match sightseeing and tour trips and also destinations seat tickets prices. This particular really will matter to individuals holiday break budgets, even though destinations may think the blessing with a lot more footfall. This kind of should be described as a increase regarding everyone.        walking tours

0

threads

112

posts

322

credits

Intermediate member

Rank: 3Rank: 3

credits
322
Published in 2022-4-2 04:57:29 | Show all floors
Thank you regarding offering latest revisions about the problem, My partner and i enjoy examine a lot more.        walking tours

0

threads

25

posts

179

credits

Registered member

Rank: 2

credits
179
Published in 2022-6-21 20:26:52 | Show all floors
Suncentauto has a large selection of quality used car parts for sale, including wheels, tires, brakes, shocks, exhaust systems and more. We have over 20 million cars listed on our website and thousands of new parts added every month! Our site (www.suncentauto.com/roof-rack-cargo-carrier.html) is updated daily with new listings from nationwide dealerships and private sellers in your area!

0

threads

18

posts

190

credits

Registered member

Rank: 2

credits
190
Published in 2023-8-5 00:06:13 | Show all floors
The best TV for a camper should have versatile mounting options, and I'm thrilled with the space-saving solutions of my chosen model. https://fittvhub.com/best-75-inch-tv-under-2000/
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list