Software Installation, Updating and Uninstallation ............. 7 Install Software ...................... 7 Update Software ....................7 Uninstall Software ....................7 Mounting Witty Pi 4 on Raspberry Pi ................. 8 Software Usage ....................... 11 Write system time to RTC ..................11 Write RTC time to system ..................12 Synchronize time ....................
Page 3
Witty Pi Log Files ......................35 Frequently Asked Questions (FAQ) ................36 15.1 What I2C address is used by Witty Pi 4? Can I change it? ........36 15.2 What I C Registers are provided by Witty Pi 4? ........... 37 15.3...
1.1 Accurate Realtime Clock and ON/OFF Scheduling The realtime clock (RTC) on Witty Pi 4 has been calibrated in the factory and Witty Pi 4’s firmware also makes temperature compensation for the crystal. This makes the RTC very accurate and the actual annual error is limited within ±2ppm (about 1 minute per year).
Witty Pi installed. 1.2 Temperature Controlled Device The temperature sensor on Witty Pi 4 has 0.125 ° C resolution. The temperature data is used for compensating the crystal and make the RTC more accurate.
1.3 DC/DC Converter and e-Latching Power Switch Witty Pi 4 comes with a DC/DC converter on board, which allows you to power your device with 6~30V power supply. You can also power your device with 5V via the USB type C connector.
1.4 Interface Introduction Witty Pi 4 supports all Raspberry Pi models that has the 40-pin GPIO header, including A+, B+, 2B, Zero, Zero W, Zero 2 W, 3B, 3B+, 3A+ and 4B. You will need to solder the 40-pin header to Zero/Zero W/Zero 2 W model beforehand, so they can make reliable connection with Witty Pi.
Operating Temperature -30° C~80° C (-22° F~176° F) Environment Humidity 0~80%RH, no condensing, no corrosive gas 3. Package Content Each package of Witty Pi 4 contains: Witty Pi 4 board x 1 30cm 22AWG XH2.54 cable x 1 ...
4. How Does Witty Pi Work? The diagram below shows the basic workflow of how Witty Pi turns on/off your Raspberry Pi. After you tap the button on Witty Pi, it powers your Raspberry Pi via the GPIO header, and your Raspberry Pi will boot.
BASH programing. 5.1 Install Software To install the software, please run this command to download the installation script: pi@raspberrypi:~ $ wget https://www.uugear.com/repo/WittyPi4/install.sh Then you can run the command below to install the software: pi@raspberrypi:~ $ sudo sh install.sh We use “sudo”...
You can directly mount Witty Pi 4 on your Raspberry Pi’s 2x20pin header, and it will work. However, if you wish, you can use the copper standoffs and screws in the package to firmly mount Witty Pi 4 on your Raspberry Pi.
Page 13
If your Witty Pi is always powered, you may omit this battery and Witty Pi's functionalities will not get affected. After mounting Witty Pi 4 on your Raspberry Pi, you can connect power supply to Witty Pi 4 (via the...
Page 14
Witty Pi will power your Raspberry Pi via the GPIO header, and that is how it performs the power management. When your Witty Pi is powered, you can see the white LED blinks for every few seconds, which means it is standing Now your Witty Pi 4 is ready to go.
./wittyPi.sh ================================================================================ Witty Pi - Realtime Clock + Power Management for Raspberry Pi < Version 4.00 > by Dun Cat B.V. (UUGear) ================================================================================ >>> Current temperature: 35.625°C / 96.125°F >>> Your system time is: 2022-05-15 11:14:18 CEST >>> Your RTC time is: 2022-05-15 11:14:17 CEST >>>...
However, you can use schedule script to do what “??” wildcard does. Please refer the Migrating from Witty Pi 3 to Witty Pi 4 chapter. Schedule script can actually make much more complex schedule. You can find more details in Schedule Script section.
After you select the “Choose schedule script” option, it will list all schedule scripts in the “schedules” folder. You can choose one, and then Witty Pi will load and run it. If you want to confirm what the script is doing, you can check the “schedule.log” file in the “~/wittypi” directory, when your Raspberry Pi is running.
7.9 Set over temperature action Here you can specify what to do if temperature exceeds a preset threshold. It does nothing by default, but you can choose to shut down or startup your Raspberry Pi when this event happens. The action you chose will be triggered when the temperature is higher than the temperature you input.
What is (pulsing) dummy load? It is a trick to keep power bank alive, when Raspberry Pi is off. If you are using power bank to power Witty Pi 4 + Raspberry Pi, after turning off Raspberry Pi and cut the power, Witty Pi 4 only draws about 1mA from the power bank, which is way too small to keep the power bank alive.
Clear low voltage threshold: The low voltage threshold will be unset. Clear recovery voltage threshold The recovery voltage threshold will be unset. Clear over temperature action The over temperature action will be cleared. Clear below temperature action The below temperature action will be cleared.
“diagnose.sh” script in “uwi” directory to do so automatically. also pi@raspberrypi:~/uwi $ ./diagnose.sh In UWI, your Witty Pi 4 device is presented like this: Here you can monitor and control your Witty Pi 4 device like using a website.
9. About Schedule Script Besides manually schedule the next shutdown/startup time, you can also use a schedule script to plan the ON/OFF sequence for your Raspberry Pi. A schedule script is a text file with .wpi file extension. Witty Pi’s software will load and execute it automatically after Raspberry Pi is boot up. 9.1 How does Schedule Script Work? A schedule script defines a loop, and it put a serial of ON/OFF states into it.
Page 23
Please keep in mind that, running the same schedule script at different moment may get different result, as the “runScript.sh” will search and find the proper state according to current time. When the “runScript.sh” is executed, if the current time is located at an “OFF” state instead, it will take the next “ON”...
9.2 Make Your Own Schedule Script A schedule script is actually a text file, and you can use any text editor to create and edit it. Below is a very simple schedule script and it will keep your Raspberry Pi on for 5 minutes in every 20 minutes.
Page 25
Sometimes you may want to skip certain scheduling of shutdown/startup, and let your own program to do the job. This can be achieved by using the WAIT syntax. For example: M15 WAIT This will keep your Raspberry Pi ON and no shutdown will be scheduled after 15 minutes, because there is a WAIT at the end of the line.
You can also use our web application to create your schedule script. Just simply open this URL in your web browser: https://www.uugear.com/app/wittypi-scriptgen/ This web application allows you to visually create the schedule script, and it immediately generate the final code on the right.
9.4 Advanced Usage of Schedule Script Besides choosing the schedule script from wittyPi.sh, you can also use schedule script without the help from wittyPi.sh. Just copy the schedule script file to “~/wittypi/schedule.wpi” and then run “./runScript.sh” in the “~/wittypi” directory, the script will start to work. This allows you to use schedule script as an interface, to integrate other tools with Witty Pi together.
Every package of Witty Pi 4 includes a CR2032 battery. You can put this battery into the battery holder on Witty Pi 4, so the realtime clock can still keep the correct time after you disconnect power supply from Witty Pi 4.
Page 29
Temperature - Frequency Error º C The orange curve is the actual measured temperature – frequency error curve. Witty Pi 4’s firmware uses the green four-segment line to approximate the actual curve for temperature compensation.
11. Additional Interfaces 11.1 The Unpopulated 3-Pin Header (P2) On the right edge of Witty Pi 4 board, there is an unpopulated 3-pin header, and you can solder a male or female connector here. This header is for inputting voltage to power Witty Pi. It will be useful if you neither want to input 5V via the USB Type C connector, nor input higher voltage via the XH2.54 connector.
Page 31
SW / SWITCH It is the signal line that connects to the switch (button) on Witty Pi 4. It is also directly connected to GPIO-4 in Raspberry Pi’s GPIO header. If you want to connect your own (2-lead) switch, you may wire the two leads to SWITCH/GPIO-4 and GND pins.
/ 0.05 = 20 * V It is the ground of Witty Pi 4 board, and it directly connects to the GND wire of power supply. 11.3 The Unpopulated 2 x 3 Pin Headers (P4) This is the In-Circuit Serial Programming (ICSP) header for uploading the firmware to the micro controller.
These are the SCL and SDA for internal I2C bus. The RTC and temperature sensor are directly connected to this internal I2C bus. It is the ground of Witty Pi 4 board, and it directly connects to the GND wire of power supply.
11.5 The Unpopulated 2-Pin Header (P6) Usually you don’t need to worry about the CR2032 battery because it can last for years. However, if you want to use a different 3V power source, you can make use of this header. The two pins of this header directly connect to the two poles of CR2032 battery.
12. Integrate with Other Programs Witty Pi’s software is written in BASH, and it is very easy to modify and integrate with other programs. The daemon.sh script is registered to be executed after boot, and this registration was done by the installation script (using update-rc.d command).
Page 36
[ "$(/usr/bin/hostname -I)" = "" ]; do /usr/bin/sleep 1 done /usr/bin/wget "https://www.uugear.com/” >/home/pi/wittypi/wget.log 2>&1 This code snippet waits for network and then query the webpage from UUGear’s website. Please notice the full path for commands and files. hostname /usr/bin/hostname sleep /usr/bin/sleep wget ...
13. Migrating from Witty Pi 3 to Witty Pi 4 If you have been using Witty Pi 3 before, migrating to Witty Pi 4 will be quite easy to you. Witty Pi 4 has the same shape factor like Witty Pi 3, and the locations of button and connectors are the same.
Page 38
Witty Pi 3 exposes two I2C devices to the bus (address 0x68 and 0x69), while Witty Pi 4 exposes only one I2C devices to the bus (default address is 0x08, can be changed). In Witty Pi 4, the I2C registers in RTC and temperature sensor are mapped to “What I...
14. Witty Pi Log Files In the directory that you install your Witty Pi software, you can find two log files: schedule.log wittyPi.log. If you need our help for solving a problem, please kindly put the log files in email attachment too.
[ "$value" == "08" ]; The final step is to shut down your Raspberry Pi, fully disconnect the power supply of your Witty Pi 4, and then reconnect the power supply. Then the MCU will start working with new address.
Normal I C registers Virtual I C registers The table below shows the registers provided by Witty Pi 4. As you can see, some of them are read-only (cannot be changed, or can only be updated by the firmware itself):...
Page 42
Index Description Range Default Accessible Firmware ID 0x26 Read-only Integer part for input voltage 0~255 Read-only Decimal part (multiple 100 times) for input 0~99 Read-only voltage Integer part for output voltage 0~255 Read-only Decimal part (multiple 100 times) for output 0~99 Read-only voltage...
Page 43
The reason code for latest action. Read-only 0 = N/A 1 = ALARM1 2 = ALARM2 3 = Button is clicked 4 = Input voltage too low 5 = Input voltage is restored 6 = over temperature ...
Page 44
the white LED The delay (multiple 10) before power cut: 0~255 Read & Write default=50 (5 seconds) Recovery voltage threshold (multiple 10, 0~255 Read & Write 255=disabled) Dummy load duration. 0 if dummy load is off. The 0~255 Read & Write bigger value, the longer time for dummy load to draw current Adjustment for measured input voltage (multiple...
Page 45
Standard value for RTC offset -127~127 Read & Write Turn on/off temperature compensation. 0 or 1 Read & Write ON = 1 OFF = 0 A flag that indicates ALARM1 (startup) is 0 or 1 Read & Write triggered and not processed.
Page 47
I register. You will need to modify the software accordingly, and reconnect the power supply to make it work. You can find more details in the “What I2C address is used by Witty Pi 4? it?” section. Can I change...
GPIO-3(SCL 1). Witty Pi 4 doesn’t actually use the TXD pin, but it will monitor its voltage. The TXD pin is supposed to be HIGH when the system is on, and should go LOW after system has been shut down. If you connect some other devices that also use the TXD pin, please make sure they don’t change this...
Please understand that we might not have the hardware you refer, and even if we have, it is difficult for us to make tests on all those hardware with Witty Pi 4. Fortunately, it is not that difficult to figure out the answer by yourself.
Page 50
Also, you can check all GPIO pin states with the command below. You need to run it in the directory that has software installed (usually “wittypi”). pi@raspberrypi:~/wittypi $ bash -c '. gpio-util.sh; gpio readall' The good GPIO states are shown below (please mind those highlighted in green). If you see something different, then it might be the culprit that causes the problem.
Page 51
1. You are using NOOBS NOOBS is not always causing this kind of problem, but the chance does exist. If you installed multiple operating systems into your Pi, the chance that NOOBS causes this problem will increase. If possible, please try not to use NOOBS. If you already use NOOBS and still try to make it work, you may set a big power cut delay value (e.g.
Page 52
4. GPIO-4 pin doesn’t reach a stable status in given time After the system is on, GPIO-4 pin should be in input mode and gets internally pulled up. However, during the startup the GPIO-4 pin could be unstable. In the daemon.sh script, the GPIO-4 listener will be started once the pin state hasn’t changed for 5 seconds.
Page 53
16. Revision History Revision Date Description 1.00 2022.06.08 Initial revision 1.01 2022.12.28 Add declaration that software is developed and tested under Raspbian. Add information about replacing CR2032 with XH2.54 cable 1.02 2023.02.24 Add description of the new #47 I2C register...
Need help?
Do you have a question about the Witty Pi 4 and is the answer not in the manual?
Questions and answers