Skip to content

Commit 23487c1

Browse files
committed
upd
1 parent 41c9816 commit 23487c1

24 files changed

+24789
-1239
lines changed

ArduinoBook/ArduinoBook.ino

-1,239
This file was deleted.

TurtleBook/TurtleBook.ino

+2,542
Large diffs are not rendered by default.
+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
//#define OLED_ENABLED
2+
#define SERIAL_ENABLED
3+
4+
#include <Wire.h>
5+
6+
#ifdef OLED_ENABLED
7+
#include <U8g2lib.h>
8+
#endif
9+
10+
#include <INA219_WE.h>
11+
#include <Arduino.h>
12+
13+
14+
#include <avr/sleep.h>
15+
#include <avr/power.h>
16+
#include <avr/wdt.h>
17+
18+
#define I2C_ADDRESS 0x40
19+
20+
float loadVoltage_V = 0.0;
21+
22+
23+
#ifdef OLED_ENABLED
24+
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* clock=*/SCL, /* data=*/SDA, /* reset=*/U8X8_PIN_NONE); // All Boards without Reset of the Display
25+
#endif
26+
27+
28+
29+
30+
31+
INA219_WE ina219 = INA219_WE(I2C_ADDRESS);
32+
// the setup function runs once when you press reset or power the board
33+
void setup() {
34+
#ifdef SERIAL_ENABLED
35+
Serial.begin(115200);
36+
37+
while (!Serial) {
38+
; // wait for serial port to connect. Needed for native USB port only
39+
}
40+
#endif
41+
42+
delay(1000);
43+
Wire.begin();
44+
45+
#ifndef SERIAL_ENABLED
46+
CLKPR = 0x80;
47+
CLKPR = 0x01;
48+
#endif
49+
//ADCSRA = 0;
50+
// prints title with ending line break
51+
#ifdef SERIAL_ENABLED
52+
Serial.println("started");
53+
//return;
54+
delay(1000);
55+
#endif
56+
57+
//ADCSRA = 0;
58+
ADCSRA &= ~(1 << ADEN);
59+
// initialize digital pin LED_BUILTIN as an output.
60+
//pinMode(LED_BUILTIN, OUTPUT);
61+
62+
pinMode(5, OUTPUT);
63+
digitalWrite(5, HIGH);
64+
if (!ina219.init()) {
65+
#ifdef SERIAL_ENABLED
66+
Serial.println("INA219 not connected!");
67+
delay(1000);
68+
#endif
69+
70+
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
71+
sleep_mode();
72+
}
73+
#ifdef SERIAL_ENABLED
74+
Serial.println("INA219 connected!");
75+
delay(1000);
76+
#endif
77+
78+
float shuntVoltage_mV = 0.0;
79+
80+
float busVoltage_V = 0.0;
81+
82+
83+
84+
shuntVoltage_mV = ina219.getShuntVoltage_mV();
85+
busVoltage_V = ina219.getBusVoltage_V();
86+
87+
loadVoltage_V = busVoltage_V + (shuntVoltage_mV / 1000);
88+
#ifdef SERIAL_ENABLED
89+
Serial.println("test"); // print as an ASCII-encoded decimal
90+
91+
// print it out in many formats:
92+
Serial.println(busVoltage_V); // print as an ASCII-encoded decimal
93+
Serial.println(shuntVoltage_mV); // print as an ASCII-encoded decimal
94+
Serial.println(loadVoltage_V); // print as an ASCII-encoded decimal
95+
delay(1000);
96+
97+
98+
99+
#endif
100+
ina219.powerDown();
101+
//ina219.powerUp();
102+
#ifdef OLED_ENABLED
103+
u8g2.begin();
104+
//u8g2.setContrast(0x5);
105+
u8g2.setFlipMode(1);
106+
u8g2.clearBuffer();
107+
108+
u8g2.setFont(u8g2_font_logisoso18_tr); // choose a suitable font
109+
u8g2.drawStr(0, 25, "V");
110+
111+
u8g2.setCursor(55, 25);
112+
u8g2.print(u8x8_u8toa(loadVoltage_V, 3));
113+
114+
115+
u8g2.sendBuffer();
116+
delay(500);
117+
#endif
118+
}
119+
120+
121+
// the loop function runs over and over again forever
122+
int t = 0;
123+
void loop() {
124+
125+
//return;
126+
/*if(t==HIGH)t=LOW;
127+
else t=HIGH;
128+
digitalWrite(LED_BUILTIN, t); // turn the LED on (HIGH is the voltage level)
129+
*/
130+
float shuntVoltage_mV = 0.0;
131+
132+
float busVoltage_V = 0.0;
133+
#ifdef OLED_ENABLED
134+
ina219.init();
135+
#endif
136+
ina219.powerUp();
137+
138+
shuntVoltage_mV = ina219.getShuntVoltage_mV();
139+
busVoltage_V = ina219.getBusVoltage_V();
140+
141+
loadVoltage_V = busVoltage_V + (shuntVoltage_mV / 1000);
142+
143+
/*if(loadVoltage_V<3.7)
144+
{
145+
digitalWrite(5, LOW); // turn the LED on (HIGH is the voltage level)
146+
}else{
147+
digitalWrite(5,HIGH); // turn the LED on (HIGH is the voltage level)
148+
}*/
149+
150+
if (loadVoltage_V >= 3.72) {
151+
digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level)
152+
}
153+
if (loadVoltage_V <= 3.69) {
154+
digitalWrite(5, LOW); // turn the LED on (HIGH is the voltage level)
155+
}
156+
/*if(t==HIGH)t=LOW;
157+
else t=HIGH;
158+
digitalWrite(5, t); // turn the LED on (HIGH is the voltage level)
159+
*/
160+
ina219.powerDown();
161+
#ifdef OLED_ENABLED
162+
163+
u8g2.begin();
164+
u8g2.clearBuffer();
165+
166+
u8g2.setFont(u8g2_font_logisoso18_tr); // choose a suitable font
167+
u8g2.drawStr(0, 25, "V");
168+
169+
u8g2.setCursor(55, 25);
170+
u8g2.print(loadVoltage_V, 3);
171+
172+
173+
u8g2.sendBuffer();
174+
delay(2000);
175+
#endif
176+
177+
#ifdef SERIAL_ENABLED
178+
179+
Serial.println("test"); // print as an ASCII-encoded decimal
180+
181+
// print it out in many formats:
182+
Serial.println(busVoltage_V); // print as an ASCII-encoded decimal
183+
Serial.println(shuntVoltage_mV); // print as an ASCII-encoded decimal
184+
Serial.println(loadVoltage_V); // print as an ASCII-encoded decimal
185+
delay(1000);
186+
#endif
187+
188+
wdt_enable(WDTO_8S); //Задаем интервал сторожевого таймера (2с)
189+
WDTCSR |= (1 << WDIE); //Устанавливаем бит WDIE регистра WDTCSR для разрешения прерываний от сторожевого таймера
190+
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
191+
sleep_mode();
192+
193+
194+
//delay(1000); // wait for a second
195+
//digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
196+
// delay(1000); // wait for a second
197+
}
198+
199+
ISR(WDT_vect) {
200+
wdt_disable();
201+
//f = !f;
202+
}

0 commit comments

Comments
 (0)