-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPico2.html
188 lines (157 loc) · 4.59 KB
/
Pico2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Raspberry Pi Pico 2 OLED Project Code</title>
<style>
body {
font-family: "Courier New", monospace;
background-color: #0d0d0d;
color: #00ff00;
margin: 20px;
}
h1, h2, h3, p {
color: #00ff00;
}
ul {
color: #00ff00;
}
pre {
background-color: #1a1a1a;
color: #00ff00;
padding: 10px;
border: 1px solid #333333;
overflow-x: auto;
}
.credit {
margin-top: 30px;
font-size: 0.9em;
color: #33cc33;
}
.pico-image {
margin-top: 20px;
border: 2px solid #00ff00;
max-width: 100%;
height: auto;
}
.back-button {
margin-top: 20px;
padding: 10px 20px;
background-color: #1a1a1a;
color: #00ff00;
border: 1px solid #00ff00;
cursor: pointer;
font-size: 1em;
}
.back-button:hover {
background-color: #00ff00;
color: #0d0d0d;
}
.copy-button {
display: inline-block;
margin: 10px 0;
padding: 5px 10px;
background-color: #00ff00;
color: #0d0d0d;
border: 1px solid #00ff00;
cursor: pointer;
font-size: 0.9em;
}
.copy-button:hover {
background-color: #1a1a1a;
color: #00ff00;
}
/* Google Translate Dropdown */
#google_translate_element {
margin-top: 20px;
text-align: center;
font-family: Arial, sans-serif;
}
.goog-te-banner-frame.skiptranslate {
display: none !important;
}
</style>
</head>
<body>
<h1>Raspberry Pi Pico 2 Project Code and Wiring Instructions</h1>
<h2>Instructions</h2>
<p>Use this code to display "Welcome to Coding" on an OLED connected to a Raspberry Pi Pico 2. The code also reads values from a DHT11 temperature and humidity sensor and an MQ gas sensor.</p>
<h3>Code for Raspberry Pi Pico 2</h3>
<p>Copy the code below into the Arduino IDE and upload it to your Raspberry Pi Pico 2:</p>
<pre id="code-block">
#include <U8g2lib.h>
#include <DHT.h>
// Define sensor pins
#define MQ_PIN 26 // Analog pin for MQ sensor
#define DHT_PIN 28 // Digital pin for DHT11 sensor
// Initialize U8g2 for the OLED display
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Adjust based on your OLED type
// DHT sensor settings
DHT dht(DHT_PIN, DHT11); // Initialize DHT11, change to DHT22 if necessary
void setup() {
Serial.begin(115200);
// Initialize the OLED
u8g2.begin();
// Initialize the DHT sensor
dht.begin();
}
void loop() {
// Read temperature and humidity
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Read analog value from MQ sensor
int mqValue = analogRead(MQ_PIN);
// Clear the display
u8g2.clearBuffer();
// Display welcome message
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.setCursor(0, 10);
u8g2.print("Welcome to Coding");
// Display sensor values
u8g2.setCursor(0, 30);
u8g2.print("Temp: ");
u8g2.print(temperature);
u8g2.print(" C");
u8g2.setCursor(0, 45);
u8g2.print("Humidity: ");
u8g2.print(humidity);
u8g2.print(" %");
u8g2.setCursor(0, 60);
u8g2.print("MQ Value: ");
u8g2.print(mqValue);
// Send buffer to the display
u8g2.sendBuffer();
delay(2000); // Update every 2 seconds
}
</pre>
<button class="copy-button" onclick="copyCode()">Copy Code</button>
<h3>Project Image</h3>
<img src="Pico2.jpg" alt="Raspberry Pi Pico 2 Wiring" class="pico-image">
<button class="back-button" onclick="location.href='index.html';">Back to Home</button>
<div class="credit">
<p>Created with the help of ChatGPT.</p>
</div>
<!-- Google Translate Dropdown -->
<div id="google_translate_element"></div>
<!-- Google Translate script -->
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en',
includedLanguages: 'en,es,fr,de,ja,ko',
layout: google.translate.TranslateElement.InlineLayout.SIMPLE
}, 'google_translate_element');
}
function copyCode() {
const codeBlock = document.getElementById('code-block').textContent;
navigator.clipboard.writeText(codeBlock).then(() => {
alert('Code copied to clipboard!');
}).catch(err => {
console.error('Failed to copy code:', err);
});
}
</script>
<script type="text/javascript" src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</body>
</html>