Category

Coding Laboratory

How to Get M5Stack Battery Status with UIFlow 1.3.2 MicroPython

By | Coding Laboratory, Python Code

Recently I’ve got my hands on the M5Stack Core device. This device, not only brought possibilities of awesome ideas, but also bring me close to the world of MicroPython. For those who are unaware, MicroPython is software implementation of Programming language largely compatible with Python 3. In short, MicroPython is Python Compiler which can run on Microcontroller.

In this post, we will use MicroPython’s “machine” library for accessing i2c bus of the M5Stack Core. The battery circuit of M5Stack core is composed of IC IP5306, which provides i2c interface at 0x75 address with Battery Percentage of 0%, 25%, 50%, 75% and 100%.

To get started, UIFlow 1.3.2 firmware need to be flashed to the M5Stack Core device.

Flashing UIFlow 1.3.2 and connecting the M5Stack device in USB Mode

You can watch video till (2 Minutes 5 Sec) https://www.youtube.com/watch?v=Y9pOWgsNgKk for Flashing and connecting the M5Stack device in USB Mode.

Running Program

While device is connected with your Computer/Laptop in USB Mode, run UI Flow Desktop IDE. It will prompt for Connecting the IDE with device. Set the correct com port and you should be good to go for running the program. Select Python Mode and use the following code to access i2c bus and get the device’s battery status

Run the code and voila! you can now get battery statistics on the screen.

RTC Clock [ DS3231 ] and FM Receiver [ TEA5767 ] Experiment

By | Arduino Code

Preface:

I've always fancy of using battery power devices, I run many of the my projects on Battery only, which are powered by Solar Panel(s). Music has very important place in my day to day life, and I didn't have any speaker which can run on battery. Hence I purchased Audio amp (PAM8403), and made a custom speaker powered by 5v DC. Although plugged to Raspberry Pi 1 B+ and using Internet Radio Stream, I found it very interrupting whenever there is a power cut. As my routers are not powered by Battery, there is Internet disconnection to Raspberry Pi and I can not play Internet Radio.

Hence to the call of the requirement, I purchased TEA5767 Module with Antenna and Audio Jack. Since I am planning to do some alarm clock type music system, which will turn on at required time and turn off in night, hence I added DS3231 RTC Module.

In future I might consider controlling it via wireless system (ESP8266 or NRF24l01). But let start this project with simple demo. Both of the module use I2C interface hence I used to share the wires between them.

Libraries:

Default installed library : https://www.arduino.cc/en/Reference/Wire

I've used following Library, which were not installed by default.

Library for DS3231(Available for install via Library Manger in Arduino): https://github.com/adafruit/RTClib

Library for TEA5767 : https://github.com/mroger/TEA5767

Pinouts:

BoardI2C pins of DS3231 and TEA5767
Uno, EthernetA4 (SDA), A5 (SCL)
Mega256020 (SDA), 21 (SCL)
Leonardo2 (SDA), 3 (SCL)
Due20 (SDA), 21 (SCL), SDA1, SCL1
5vVcc
GNDGnd

--

--

Project Description:

After pushing the code to microcontroller (Arduino Uno in my case), the default station set in the code is played. I open Serial Console, set baud rate at 115200 and send the desired frequency between 88MHz to 108MHz, and press send button. It play that FM station. Alternatively I can use to send "+" or  "-" keys, to scan FM frequency and halt whenever a broadcasting frequency is found.

Final Word:

There are other options like Mute sound, or put device to sleep in the GitHub code of TEA5767 which I have not included in this code.

Yes this is not consumer friendly project, as there is no option of controlling the device easily. The device can have option of using buttons or using wireless communication methods. I'll leave that part of exploration with my dear readers. Feel free to contact me via https://ikunal.in/contact/