-
• #27
This initialisation code seems to work - it turns the backlight on, charges the battery etc. Needs to be put into a module when time permits. You can get the battery voltage and current using
batV
andbatA
:I2C1.setup({scl:22,sda:21,bitrate:400000}); function init(){ function Write1Byte(a,d) { I2C1.writeTo(0x34,a,d);} // Set LDO2 & LDO3(TFT_LED & TFT) 3.0V Write1Byte(0x28, 0xcc); // Set ADC to All Enable Write1Byte(0x82, 0xff); // Bat charge voltage to 4.2, Current 100MA Write1Byte(0x33, 0xc0); // Enable Bat,ACIN,VBUS,APS adc Write1Byte(0x82, 0xff); // Enable Ext, LDO3, DCDC1 // Close DCDC2 output // with out LD02 LCD light it is 0x49 Write1Byte(0x12, 0x4D); // 128ms power on, 4s power off Write1Byte(0x36, 0x0C); // Set RTC voltage to 3.3V Write1Byte(0x91, 0xF0); // Set GPIO0 to LDO Write1Byte(0x90, 0x02); // Disable vbus hold limit Write1Byte(0x30, 0x80); // Set temperature protection Write1Byte(0x39, 0xfc); // Enable RTC BAT charge Write1Byte(0x35, 0xa2); // Enable bat detection Write1Byte(0x32, 0x46); } init(); function batV() { I2C1.writeTo(0x34,0x78); var d = I2C1.readFrom(0x34,2); var v = d[0]*16+d[1]; const ADCLSB = 1.1 / 1000.0; return v * ADCLSB; } function batA() { function read13(a){ I2C1.writeTo(0x34,a); var d = I2C1.readFrom(0x34,2); return d[0]*32+d[1]; } // current in - current out (ma); return ( read13(0x7A)-read13(0x7C))/2; }
-
• #28
Thanks, I can confirm this does indeed activate the power management functions and allows the USB to charge the battery :)
-
• #30
This is what I just started for a M5StickC:
require('Storage').write('.boot1',` global.M5C = { BTNA: D37, BTNB: D39, LED: D10, IR: D9, lcd: { // AXP192: { id: 0x34 }, LD02: power lcd, LD03: lcd on power: (state) => { M5C.lcd.flipBit(state, 2); }, backlight: (state) => { M5C.lcd.flipBit(state, 4); }, flipBit: (state, bit) => { I2C1.setup({ scl: D22, sda: D21 }); I2C1.writeTo(0x34, 0x12); buf = I2C1.readFrom(0x34, 0x12, 1)[0]; if (state) I2C1.writeTo(0x34, 0x12, buf | bit); else I2C1.writeTo(0x34, 0x12, buf & ~bit); } }, header: { Grove: [D32, D33], Front: [D26, D36, D0] } };`);
-
• #31
Is there a way to create a custom .hex that runs code on startup? I know we can add modules ourselves so it's already available in the firmware without internet access, but in this case can we automatically add code to .boot1 for example during the .hex flashing process?
I charged my M5StickC to full and flashed a blinky sketch. It's been working just fine (including console log of the time) for hours now.
Have you tried charging yours fully?
It would be nice to get some bindings with the AXP192 though, as it also controls the backlight of the LCD :P It's using the st7735 but without the backlight getting power, we can't see anything on the screen (or at least that's what I think; maybe I'm just using the lcd wrong).
Would also be nice if we can somehow get something like https://www.espruino.com/Reference#l_NRF_getBattery working through the power management chip :P