Skip to content

Commit 96321ce

Browse files
Merge pull request #1406 from arduino/sync/Hannes7eicher/giga-example-fix
[MKC-1070] Hannes7eicher/giga example fix
2 parents 7fe0a9b + 50fdee1 commit 96321ce

File tree

8 files changed

+195
-87
lines changed

8 files changed

+195
-87
lines changed

content/hardware/10.mega/boards/giga-r1-wifi/tutorials/cheat-sheet/cheat-sheet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tags:
1515
- Audio Jack
1616
author: 'Jacob Hylén'
1717
hardware:
18-
- hardware/08.mega/boards/giga-r1-wifi
18+
- hardware/10.mega/boards/giga-r1-wifi
1919
software:
2020
- ide-v1
2121
- ide-v2

content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-audio/content.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
title: Guide to GIGA R1 Advanced ADC/DAC and Audio Features
33
description: 'Learn how to use the ADC/DAC features, along with useful examples on how to generate waveforms and play audio from a file.'
44
author: José Bagur, Taddy Chung & Karl Söderby
5+
hardware:
6+
- hardware/10.mega/boards/giga-r1-wifi
7+
software:
8+
- ide-v1
9+
- ide-v2
10+
- web-editor
511
tags: [ADC, DAC, Audio, USB]
612
---
713

content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-camera/giga-camera.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ title: GIGA R1 Camera Guide
33
description: Learn about the GIGA R1 WiFi's camera connector, and how to use existing examples.
44
tags: [ArduCAM, Camera, Processing]
55
author: Karl Söderby
6+
hardware:
7+
- hardware/10.mega/boards/giga-r1-wifi
8+
software:
9+
- ide-v1
10+
- ide-v2
11+
- web-editor
612
---
713

814
The GIGA R1 has a dedicated camera connector that allows certain camera modules to mount directly on the board. This makes it possible to add machine vision to your GIGA R1 board without much effort at all.

content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/giga-dual-core.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
title: Guide to GIGA R1 Dual Cores
33
description: Learn how to access and control the M4 and M7 cores on the GIGA R1, and how to communicate between them using RPC.
44
author: Karl Söderby
5+
hardware:
6+
- hardware/10.mega/boards/giga-r1-wifi
7+
software:
8+
- ide-v1
9+
- ide-v2
10+
- web-editor
511
tags: [Dual Core, M4, M7]
612
---
713

content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-getting-started/giga-getting-started.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
title: Getting Started with GIGA R1 WiFi
33
description: A step-by-step guide to install the board package needed for the GIGA R1 WiFi board.
44
author: Karl Söderby
5+
hardware:
6+
- hardware/10.mega/boards/giga-r1-wifi
7+
software:
8+
- ide-v1
9+
- ide-v2
10+
- web-editor
511
tags: [GIGA R1 WiFi, Installation, IDE]
612
---
713

content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-micropython/giga-micropython.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
title: MicroPython on the GIGA R1
33
description: Get started with MicroPython on the GIGA R1.
44
author: Karl Söderby
5+
hardware:
6+
- hardware/10.mega/boards/giga-r1-wifi
57
tags: [MicroPython, dfu-util]
68
---
79

content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-usb/giga-usb.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
title: Guide to Arduino GIGA USB Features
33
description: 'Learn how you can turn your USB device into a mouse or keyboard, how to read & write to a USB mass storage, and connecting a keyboard via the USB-A connector.'
44
author: Karl Söderby
5+
hardware:
6+
- hardware/10.mega/boards/giga-r1-wifi
7+
software:
8+
- ide-v1
9+
- ide-v2
10+
- web-editor
511
tags: [USB, USB HID, USBHost, Mass Storage, Keyboard, Mouse]
612
---
713

content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-wifi/giga-wifi.md

Lines changed: 162 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
title: GIGA R1 WiFi Network Examples
33
description: Discover examples compatible with the WiFi library included in the GIGA core.
44
author: Karl Söderby
5+
hardware:
6+
- hardware/10.mega/boards/giga-r1-wifi
7+
software:
8+
- ide-v1
9+
- ide-v2
10+
- web-editor
511
tags: [Wi-Fi, Web Server, AP Mode, SSL, UDP]
612
---
713

@@ -156,117 +162,187 @@ void printMacAddress(byte mac[]) {
156162

157163
```arduino
158164
/*
159-
This example connects to an unencrypted WiFi network.
160-
Then it prints the MAC address of the WiFi module,
161-
the IP address obtained, and other network details.
165+
Udp NTP Client
162166
163-
Circuit:
164-
* GIGA R1 WiFi
167+
Get the time from a Network Time Protocol (NTP) time server
168+
Demonstrates use of UDP sendPacket and ReceivePacket
169+
For more on NTP time servers and the messages needed to communicate with them,
170+
see http://en.wikipedia.org/wiki/Network_Time_Protocol
165171
166-
created 13 July 2010
167-
by dlf (Metodo2 srl)
168-
modified 31 May 2012
172+
created 4 Sep 2010
173+
by Michael Margolis
174+
modified 9 Apr 2012
169175
by Tom Igoe
170-
modified 22 March 2023
171-
by Karl Söderby
172-
*/
176+
modified 28 Dec 2022
177+
by Giampaolo Mancini
173178
179+
This code is in the public domain.
180+
*/
174181
175-
#include <SPI.h>
176182
#include <WiFi.h>
183+
#include <WiFiUdp.h>
184+
#include <mbed_mktime.h>
177185
178-
#include "arduino_secrets.h"
186+
int status = WL_IDLE_STATUS;
187+
#include "arduino_secrets.h"
179188
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
180-
char ssid[] = SECRET_SSID; // your network SSID (name)
181-
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
182-
int status = WL_IDLE_STATUS; // the WiFi radio's status
189+
char ssid[] = ""; // your network SSID (name)
190+
char pass[] = ""; // your network password (use for WPA, or use as key for WEP)
191+
int keyIndex = 0; // your network key index number (needed only for WEP)
183192
184-
void setup() {
185-
//Initialize serial and wait for port to open:
186-
Serial.begin(9600);
187-
while (!Serial) {
188-
; // wait for serial port to connect. Needed for native USB port only
189-
}
193+
unsigned int localPort = 2390; // local port to listen for UDP packets
190194
191-
// check for the WiFi module:
192-
if (WiFi.status() == WL_NO_MODULE) {
193-
Serial.println("Communication with WiFi module failed!");
194-
// don't continue
195-
while (true);
196-
}
195+
// IPAddress timeServer(162, 159, 200, 123); // pool.ntp.org NTP server
197196
198-
// attempt to connect to WiFi network:
199-
while (status != WL_CONNECTED) {
200-
Serial.print("Attempting to connect to WPA SSID: ");
201-
Serial.println(ssid);
202-
// Connect to WPA/WPA2 network:
203-
status = WiFi.begin(ssid, pass);
197+
constexpr auto timeServer { "pool.ntp.org" };
204198
205-
// wait 10 seconds for connection:
206-
delay(10000);
207-
}
199+
const int NTP_PACKET_SIZE = 48; // NTP timestamp is in the first 48 bytes of the message
208200
209-
// you're connected now, so print out the data:
210-
Serial.print("You're connected to the network");
211-
printCurrentNet();
212-
printWifiData();
201+
byte packetBuffer[NTP_PACKET_SIZE]; // buffer to hold incoming and outgoing packets
213202
214-
}
203+
// A UDP instance to let us send and receive packets over UDP
204+
WiFiUDP Udp;
215205
216-
void loop() {
217-
// check the network connection once every 10 seconds:
218-
delay(10000);
219-
printCurrentNet();
220-
}
206+
constexpr unsigned long printInterval { 1000 };
207+
unsigned long printNow {};
221208
222-
void printWifiData() {
223-
// print your board's IP address:
224-
IPAddress ip = WiFi.localIP();
225-
Serial.print("IP Address: ");
226-
Serial.println(ip);
227-
Serial.println(ip);
209+
void setup()
210+
{
211+
// Open serial communications and wait for port to open:
212+
Serial.begin(9600);
213+
while (!Serial) {
214+
; // wait for serial port to connect. Needed for native USB port only
215+
}
228216
229-
// print your MAC address:
230-
byte mac[6];
231-
WiFi.macAddress(mac);
232-
Serial.print("MAC address: ");
233-
printMacAddress(mac);
234-
}
217+
// check for the WiFi module:
218+
if (WiFi.status() == WL_NO_SHIELD) {
219+
Serial.println("Communication with WiFi module failed!");
220+
// don't continue
221+
while (true)
222+
;
223+
}
235224
236-
void printCurrentNet() {
237-
// print the SSID of the network you're attached to:
238-
Serial.print("SSID: ");
239-
Serial.println(WiFi.SSID());
225+
// attempt to connect to WiFi network:
226+
while (status != WL_CONNECTED) {
227+
Serial.print("Attempting to connect to SSID: ");
228+
Serial.println(ssid);
229+
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
230+
status = WiFi.begin(ssid, pass);
240231
241-
// print the MAC address of the router you're attached to:
242-
byte bssid[6];
243-
WiFi.BSSID(bssid);
244-
Serial.print("BSSID: ");
245-
printMacAddress(bssid);
232+
// wait 10 seconds for connection:
233+
delay(10000);
234+
}
246235
247-
// print the received signal strength:
248-
long rssi = WiFi.RSSI();
249-
Serial.print("signal strength (RSSI):");
250-
Serial.println(rssi);
236+
Serial.println("Connected to WiFi");
237+
printWifiStatus();
238+
239+
setNtpTime();
251240
252-
// print the encryption type:
253-
byte encryption = WiFi.encryptionType();
254-
Serial.print("Encryption Type:");
255-
Serial.println(encryption, HEX);
256-
Serial.println();
257241
}
258242
259-
void printMacAddress(byte mac[]) {
260-
for (int i = 5; i >= 0; i--) {
261-
if (mac[i] < 16) {
262-
Serial.print("0");
243+
void loop()
244+
{
245+
if (millis() > printNow) {
246+
Serial.print("System Clock: ");
247+
Serial.println(getLocaltime());
248+
printNow = millis() + printInterval;
263249
}
264-
Serial.print(mac[i], HEX);
265-
if (i > 0) {
266-
Serial.print(":");
250+
}
251+
252+
void setNtpTime()
253+
{
254+
Udp.begin(localPort);
255+
sendNTPpacket(timeServer);
256+
delay(1000);
257+
parseNtpPacket();
258+
}
259+
260+
// send an NTP request to the time server at the given address
261+
unsigned long sendNTPpacket(const char * address)
262+
{
263+
memset(packetBuffer, 0, NTP_PACKET_SIZE);
264+
packetBuffer[0] = 0b11100011; // LI, Version, Mode
265+
packetBuffer[1] = 0; // Stratum, or type of clock
266+
packetBuffer[2] = 6; // Polling Interval
267+
packetBuffer[3] = 0xEC; // Peer Clock Precision
268+
// 8 bytes of zero for Root Delay & Root Dispersion
269+
packetBuffer[12] = 49;
270+
packetBuffer[13] = 0x4E;
271+
packetBuffer[14] = 49;
272+
packetBuffer[15] = 52;
273+
274+
Udp.beginPacket(address, 123); // NTP requests are to port 123
275+
Udp.write(packetBuffer, NTP_PACKET_SIZE);
276+
Udp.endPacket();
277+
}
278+
279+
unsigned long parseNtpPacket()
280+
{
281+
if (!Udp.parsePacket())
282+
return 0;
283+
284+
Udp.read(packetBuffer, NTP_PACKET_SIZE);
285+
const unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
286+
const unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
287+
const unsigned long secsSince1900 = highWord << 16 | lowWord;
288+
constexpr unsigned long seventyYears = 2208988800UL;
289+
const unsigned long epoch = secsSince1900 - seventyYears;
290+
set_time(epoch);
291+
292+
#if defined(VERBOSE)
293+
Serial.print("Seconds since Jan 1 1900 = ");
294+
Serial.println(secsSince1900);
295+
296+
// now convert NTP time into everyday time:
297+
Serial.print("Unix time = ");
298+
// print Unix time:
299+
Serial.println(epoch);
300+
301+
// print the hour, minute and second:
302+
Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT)
303+
Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
304+
Serial.print(':');
305+
if (((epoch % 3600) / 60) < 10) {
306+
// In the first 10 minutes of each hour, we'll want a leading '0'
307+
Serial.print('0');
267308
}
268-
}
269-
Serial.println();
309+
Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
310+
Serial.print(':');
311+
if ((epoch % 60) < 10) {
312+
// In the first 10 seconds of each minute, we'll want a leading '0'
313+
Serial.print('0');
314+
}
315+
Serial.println(epoch % 60); // print the second
316+
#endif
317+
318+
return epoch;
319+
}
320+
321+
String getLocaltime()
322+
{
323+
char buffer[32];
324+
tm t;
325+
_rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT);
326+
strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t);
327+
return String(buffer);
328+
}
329+
330+
void printWifiStatus()
331+
{
332+
// print the SSID of the network you're attached to:
333+
Serial.print("SSID: ");
334+
Serial.println(WiFi.SSID());
335+
336+
// print your board's IP address:
337+
IPAddress ip = WiFi.localIP();
338+
Serial.print("IP Address: ");
339+
Serial.println(ip);
340+
341+
// print the received signal strength:
342+
long rssi = WiFi.RSSI();
343+
Serial.print("signal strength (RSSI):");
344+
Serial.print(rssi);
345+
Serial.println(" dBm");
270346
}
271347
```
272348

0 commit comments

Comments
 (0)