You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Library/Others.md
+216-2Lines changed: 216 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ These examples illustrate more complex, yet fundamental, applications of multipl
17
17
18
18
## Basic Ultrasound Examples
19
19
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.
21
21
22
22
{: .IMPORTANT}
23
23
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
**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.
167
167
168
168
```matlab
169
169
function data = read_data(arduino, data_length)
@@ -303,6 +303,220 @@ Second figure shows measurements with a flat object placed near the board. Here,
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.
309
+
310
+
**Step 1**{: .text-blue-000} : Include SensEdu and WiFi libraries.
311
+
312
+
```c
313
+
#include"SensEdu.h"
314
+
#include<WiFi.h>
315
+
```
316
+
317
+
**Step 2**{: .text-blue-000} : Create a lookup table (LUT) that contains a sine wave.
318
+
319
+
```c
320
+
constuint16_t dac_cycle_num = 10; // sine cycles
321
+
322
+
constuint16_t sine_lut_size = 64; // sine wave size
**Step 3**{: .text-blue-000} : Initialize the `SensEdu_DAC_Settings` struct with DAC parameters. Refer to [DAC page]({% link Library/DAC.md %}#sensedu_dac_settings) for details.
336
+
337
+
```c
338
+
#define DAC_SINE_FREQ 32000 // 32kHz
339
+
#define DAC_SAMPLE_RATE DAC_SINE_FREQ * sine_lut_size // 64 samples per one sine cycle
340
+
341
+
DAC_Channel* dac_ch = DAC_CH1;
342
+
SensEdu_DAC_Settings dac_settings = {
343
+
.dac_channel = dac_ch,
344
+
.sampling_freq = DAC_SAMPLE_RATE,
345
+
.mem_address = (uint16_t*)sine_lut,
346
+
.mem_size = sine_lut_size,
347
+
.wave_mode = SENSEDU_DAC_MODE_BURST_WAVE,
348
+
.burst_num = dac_cycle_num
349
+
};
350
+
```
351
+
352
+
**Step 4**{: .text-blue-000} : Initialize the `SensEdu_ADC_Settings` struct with ADC parameters. Refer to [ADC page]({% link Library/ADC.md %}#sensedu_adc_settings) for details. Array for ADC must have the proper size and be cache aligned, you can read more about this [here]({% link Library/ADC.md %}#cache-coherence).
353
+
354
+
```c
355
+
constuint16_t mic_data_size = 16*128; // must be multiple of 16 for 16bit
**Step 5**{: .text-blue-000} : Set SSID and password for your WiFi network, define a WiFi server on port 80 and a variable for its status.
376
+
377
+
```c
378
+
char *ssid = "TestWifi";
379
+
char *pass = "test1234";
380
+
uint16_t port = 80;
381
+
382
+
int status = WL_IDLE_STATUS;
383
+
384
+
WiFiServer server(port);
385
+
```
386
+
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.
388
+
389
+
```c
390
+
voidsetup() {
391
+
Serial.begin(115200);
392
+
393
+
SensEdu_DAC_Init(&dac_settings);
394
+
SensEdu_ADC_Init(&adc_settings);
395
+
SensEdu_ADC_Enable(adc);
396
+
397
+
// attempt connection to WiFi network
398
+
while (status != WL_CONNECTED) {
399
+
Serial.println(ssid);
400
+
// connect to WPA/WPA2 network (change this if youre using open / WEP network)
401
+
status = WiFi.begin(ssid, pass);
402
+
403
+
// wait 10 seconds for connection
404
+
delay(10000);
405
+
}
406
+
server.begin();
407
+
}
408
+
```
409
+
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.
412
+
413
+
```c
414
+
voidloop() {
415
+
416
+
WiFiClient client = server.available();
417
+
Serial.println("IP Address: ");
418
+
Serial.print(WiFi.localIP());
419
+
420
+
if (client) {
421
+
Serial.println("Client connected!");
422
+
static char buf = 0;
423
+
424
+
while(client.connected()){
425
+
if (client.available()) {
426
+
buf = client.read();
427
+
if(buf == 't') {
428
+
// trigger detected -> initiate measurements
429
+
// do stuff
430
+
// transmit data to PC
431
+
}
432
+
}
433
+
}
434
+
}
435
+
436
+
}
437
+
```
438
+
439
+
**Step 7**{: .text-blue-000} : Start the transmission of the sine wave and wait until it is completed.
440
+
441
+
```c
442
+
SensEdu_DAC_Enable(dac_ch);
443
+
while(!SensEdu_DAC_GetBurstCompleteFlag(dac_ch));
444
+
SensEdu_DAC_ClearBurstCompleteFlag(dac_ch);
445
+
```
446
+
447
+
**Step 8**{: .text-blue-000} : Start the data acquisition and wait until it is completed.
448
+
449
+
```c
450
+
while(!SensEdu_ADC_GetTransferStatus(adc));
451
+
SensEdu_ADC_ClearTransferStatus(adc);
452
+
```
453
+
454
+
**Step 9**{: .text-blue-000} : Send the received wave data to MATLAB via Serial.
**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.
484
+
485
+
```matlab
486
+
function data = read_data(arduino_server, data_length)
487
+
total_byte_length = data_length * 2; % 2 bytes per sample
488
+
serial_rx_data = zeros(1, total_byte_length);
489
+
490
+
for i = 1:(total_byte_length/32) % 32 bytes chunk size
**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.
0 commit comments