Skip to content

Commit c88f7ee

Browse files
committed
basic ultrasound wifi: small wiki corrections + added couple of pictures
1 parent ca880d9 commit c88f7ee

File tree

7 files changed

+38
-25
lines changed

7 files changed

+38
-25
lines changed

docs/Library/Others.md

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ These examples illustrate more complex, yet fundamental, applications of multipl
1717

1818
## Basic Ultrasound Examples
1919

20-
These examples demonstrate how to transmit a 32kHz ultrasonic wave at a constant sampling rate. The reflected wave is then captured and sent to a PC via Serial communication. Using MATLAB, you can visualize and potentially process the wave. By placing an object on top of the SensEdu, you can observe wave reflections.
20+
These examples demonstrate how to transmit a 32kHz ultrasonic wave at a constant sampling rate. The reflected wave is then captured and sent to a PC via Serial or WiFi communication. Using MATLAB, you can visualize and potentially process the wave. By placing an object on top of the SensEdu, you can observe wave reflections.
2121

2222
{: .IMPORTANT}
2323
To run these examples, you need to install [MATLAB].
@@ -163,7 +163,7 @@ DATA_LENGTH = 16*128; % ensure this value matches `mic_data_size` in firmware
163163
arduino = serialport(ARDUINO_PORT, ARDUINO_BAUDRATE);
164164
```
165165

166-
**Step 11**{: .text-blue-000} : Write a function in MATLAB to receive data from Arduino. The function should handle 16-bit samples sent in bytes, so each sample consisting of 2 bytes. In the firmware, data is sent in 32-byte chunks, and the MATLAB function should match this to avoid synchronization issues.
166+
**Step 11**{: .text-blue-000} : Write a function in MATLAB to receive the data from Arduino. The function should handle 16-bit samples sent in bytes, so each sample consisting of 2 bytes. In the firmware, data is sent in 32-byte chunks, and the MATLAB function should match this to avoid synchronization issues.
167167

168168
```matlab
169169
function data = read_data(arduino, data_length)
@@ -305,9 +305,9 @@ Second figure shows measurements with a flat object placed near the board. Here,
305305

306306
### Basic_UltraSound_WiFi
307307

308-
Utilizes WiFi for data transmission.
308+
Utilizes only one microphone. The example is similar to [Basic_UltraSound]({% link Library/Others.md %}#basic_ultrasound), but uses WiFi as communication medium instead of Serial.
309309

310-
**Step 1**{: .text-blue-000} : Include the SensEdu and WiFi libraries.
310+
**Step 1**{: .text-blue-000} : Include SensEdu and WiFi libraries.
311311

312312
```c
313313
#include "SensEdu.h"
@@ -377,13 +377,14 @@ SensEdu_ADC_Settings adc_settings = {
377377
```c
378378
char *ssid = "TestWifi";
379379
char *pass = "test1234";
380+
uint16_t port = 80;
380381
381382
int status = WL_IDLE_STATUS;
382383
383-
WiFiServer server(80);
384+
WiFiServer server(port);
384385
```
385386

386-
**Step 6**{: .text-blue-000} : Initialize DAC and ADC with created structs. Enable Serial for communication with PC (for retrieving the boards IP later). Attempt connection with the previosuly defined WiFi network.
387+
**Step 6**{: .text-blue-000} : Initialize DAC and ADC with created structs. Enable Serial for communication with PC (for retrieving the boards IP later). Attempt connection with the previously defined WiFi network.
387388

388389
```c
389390
void setup() {
@@ -395,19 +396,19 @@ void setup() {
395396

396397
// attempt connection to WiFi network
397398
while (status != WL_CONNECTED) {
398-
Serial.println(ssid);
399-
// connect to WPA/WPA2 network (change this if youre using open / WEP network)
400-
status = WiFi.begin(ssid, pass);
399+
Serial.println(ssid);
400+
// connect to WPA/WPA2 network (change this if youre using open / WEP network)
401+
status = WiFi.begin(ssid, pass);
401402

402-
// wait 10 seconds for connection
403-
delay(10000);
403+
// wait 10 seconds for connection
404+
delay(10000);
404405
}
405406
server.begin();
406407
}
407408
```
408409

409-
**Step 6**{: .text-blue-000} : Create a buffer that waits for a command (e.g., symbol "t") from MATLAB.
410-
Print your boards IP-address to serial so you can note it down later.
410+
**Step 6**{: .text-blue-000} : Create a buffer that waits for a trigger command (symbol "t") from MATLAB.
411+
Print the board's IP-address in a serial monitor, as it will be needed later.
411412

412413
```c
413414
void loop() {
@@ -423,9 +424,10 @@ void loop() {
423424
while(client.connected()){
424425
if (client.available()) {
425426
buf = client.read();
426-
if(buf == 't') { // trigger detected -> send
427-
428-
// do stuff
427+
if(buf == 't') {
428+
// trigger detected -> initiate measurements
429+
// do stuff
430+
// transmit data to PC
429431
}
430432
}
431433
}
@@ -465,7 +467,7 @@ void wifi_send_array(const uint8_t* data, size_t size, WiFiClient client) {
465467
}
466468
```
467469
468-
**Step 10**{: .text-blue-000} : Open `matlab\Basic_UltraSound_WiFi_ReadData.m`. Specify the required parameters and start the connection with your Arduino.
470+
**Step 10**{: .text-blue-000} : Open `matlab\Basic_UltraSound_WiFi_ReadData.m`. Specify the required parameters and start the connection with Arduino.
469471
470472
```matlab
471473
%% Settings
@@ -478,7 +480,7 @@ DATA_LENGTH = 16*128; % ensure this value matches `mic_data_size` in firmware
478480
arduino_server = tcpclient(ARDUINO_IP, ARDUINO_PORT);
479481
```
480482

481-
**Step 11**{: .text-blue-000} : Write a function in MATLAB to receive data from the Arduino. The function should handle 16-bit samples sent in bytes, so each sample consisting of 2 bytes. In the firmware, data is sent in 32-byte chunks, and the MATLAB function should match this to avoid synchronization issues.
483+
**Step 11**{: .text-blue-000} : Write a function in MATLAB to receive the data from Arduino. The function should handle 16-bit samples sent in bytes, so each sample consisting of 2 bytes. In the firmware, data is sent in 32-byte chunks, and the MATLAB function should match this to avoid synchronization issues.
482484

483485
```matlab
484486
function data = read_data(arduino_server, data_length)
@@ -506,6 +508,16 @@ for it = 1:ITERATIONS
506508
end
507509
```
508510

511+
**Step 13**{: .text-blue-000} : Connect your PC to the same WiFi network and run the script.
512+
513+
![]({{site.baseurl}}/assets/images/PCWiFiConnection.png)
514+
515+
**Results**{: .text-blue-000} : Below is a figure showing the measurement results.
516+
517+
Notice that with WiFi, your Serial is freed up, allowing to use it for convenient debugging purposes on Arduino or to send data in parallel to the WiFi connection.
518+
519+
![]({{site.baseurl}}/assets/images/WiFiConnection.png)
520+
509521
[STM32H747 Reference Manual]: https://www.st.com/resource/en/reference_manual/rm0399-stm32h745755-and-stm32h747757-advanced-armbased-32bit-mcus-stmicroelectronics.pdf
510522

511523
[MATLAB]: https://www.mathworks.com/products/matlab.html
30 KB
Loading

docs/assets/images/WiFiConnection.png

32.5 KB
Loading

libraries/SensEdu/examples/Basic_UltraSound_WiFi/Basic_UltraSound_WiFi.ino

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ SensEdu_ADC_Settings adc_settings = {
4444
/* WiFi settings */
4545
char *ssid = "TestWifi";
4646
char *pass = "test1234";
47+
uint16_t port = 80;
4748

4849
int status = WL_IDLE_STATUS;
4950

50-
WiFiServer server(80);
51+
WiFiServer server(port);
5152

5253
/* errors */
5354
uint32_t lib_error = 0;
@@ -75,13 +76,13 @@ void setup() {
7576

7677
// attempt connection to WiFi network
7778
while (status != WL_CONNECTED) {
78-
Serial.print("Attempting to connect to SSID: ");
79-
Serial.println(ssid);
80-
// connect to WPA/WPA2 network (change this if youre using open / WEP network)
81-
status = WiFi.begin(ssid, pass);
79+
Serial.print("Attempting to connect to SSID: ");
80+
Serial.println(ssid);
81+
// connect to WPA/WPA2 network (change this if youre using open / WEP network)
82+
status = WiFi.begin(ssid, pass);
8283

83-
// wait 10 seconds for connection:
84-
delay(10000);
84+
// wait 10 seconds for connection:
85+
delay(10000);
8586
}
8687
server.begin();
8788
// connection established; print out the status:
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)