VIM3 Android Power Suspend by Voltage Level / GPIO?

This does help, tremendously! I am using an Arduino Mega, alongside the VIM3, and had considered tapping into the LED, to gain a power status on the VIM3. I like your solution much better. Are you tapping the I2C SCL or SDA? Can you elaborate on the script? I am well versed in other embedded things, but Android scripting and programming escapes me. Thank for responding!

1 Like

I think both work but if I remember correctly I am using I2C SCL.
The code I am using on the VIM is this one:

#!/system/bin/sh
restart_usb=false
echo 'Starting Powermanagement Service...'
while true
do
	ignition=$( cat /sys/class/gpio/gpio431/value )
	enabled=$( cat /sys/class/gpio/gpio432/value )
	logcat > /logs/logcat_$(date +"%Y%m%d%H%M").txt
	if [ "$enabled" = 1 ]; then
		if [ "$ignition" = 0 ]; then
			shutdown_timer_run=true
			if [ -z $(dumpsys display | grep mScreenState=OFF) ]; then
				echo 'Going to sleep'
				echo 'mem' > /sys/power/state
				restart_usb=true
			fi
		else
			if [ "$restart_usb" = true ]; then
				echo 0 > /sys/bus/usb/devices/1-1.1/authorized
				sleep 1
				echo 1 > /sys/bus/usb/devices/1-1.1/authorized
				restart_usb=false
			fi
		fi
	fi
	sleep 1
done

The enabled part is just a jumper so I can test the device outside of the car.
I needed the restart usb part because my touchscreen wouldn’t work after it woke up from sleep, maybe you will not need this.

This is the important part of the code I am using for the ESP:

void loop() {
  VIM_PWR_VALUE = analogRead(ANALOG_PIN);

  if (VIM_PWR_VALUE < 500) {
    if (wake_vim_timer >= 1000) {
      Serial.print("Wake VIM\n");
      wake_up_vim();
      wake_vim_timer = 0;
    } else {
      wake_vim_timer++;
    }
  }
}

void wake_up_vim() {
  digitalWrite(VIM_WAKE_PIN, 1);
  delay(100);
  digitalWrite(VIM_WAKE_PIN, 0);
  delay(3000);
}
4 Likes

How are you running the script? Through terminal, or are you compiling that somehow?

I run it at start but I forgot exactly where I run it, but you have to make sure that it has root permissions

OK. I will try to do some homework on it. I sure do appreciate your willingness to help me out!

Hi @Terry

Could you please advice what need to be changed here to wake from deep sleep (or if this possible) in the following scenario

1/ Deep sleep - I want to wake up on signal change on signal received on I2C_M3_SDA or I2C_M3_SCL pin on GPIO 40 header. It seems that I need to register pin in

void get_wakeup_source(void *response, unsigned int suspend_from)

but it’s not clear how to do that - could you please advice (I’m planning to wake up board from external MCU signal - atmega328 based)

2/. Will any transmission on i2c-3 bus will wake system from early_suspend state or it needs driver change ?

This is an area that the VIM3 misses the boat as an embedded system. Without a way for positive control of the sleep state from an external controller, the VIM3 becomes an Android tablet without a screen.

I hate to be that new guy, but I am trying to setup the same as outlined by @3id_L using a ESP.

I am familiar with putting the code on the ESP using Arduino IDE. However I don’t where to start or what to search for when it comes to putting code on the VIM3 running Android (this is new to me).

Would anyone be so kind as to tell me how to go about putting the code on the VIM3, and where it should go? Or even point me to some information that may help me work it out?

Many thanks