UT 05: Get free memory
This example shows how to get the actual free memory in RAM memory.

Required Materials

1 x Waspmote 1 x Battery 1 x MiniUSB wire

Notes

This example can be executed in Waspmote v12 and Waspmote v15

Code

1
/*
2
* ------ [Ut_05] Get Free Memory --------
3
*
4
* Explanation: This example shows how to get the actual free memory
5
* in RAM memory.
6
*
7
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
8
* http://www.libelium.com
9
*
10
* This program is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see .
22
*
23
* Version: 3.0
24
* Design: David Gascón
25
* Implementation: Yuri Carmona
26
*/
27
28
char* pointer;
29
30
void setup()
31
{
32
// Init USB
33
USB.ON();
34
USB.println(F("UT_05 example"));
35
36
USB.print(F("Initial free Memory (Bytes):"));
37
USB.println(freeMemory());
38
USB.print(F("-----------------------------"));
39
40
}
41
42
void loop()
43
{
44
// See how dynamic memory consumes RAM memory during code
45
pointer = (char*)calloc(1,100);
46
47
USB.print(F("\nfree Memory:"));
48
USB.println(freeMemory());
49
50
// free memory
51
free(pointer);
52
pointer=NULL;
53
54
delay(3000);
55
}
56
57
Copied!

Output

1
H#
2
UT_05 example
3
Initial free Memory (Bytes):7508
4
-----------------------------
5
free Memory:7406
6
free Memory:7406
7
....
Copied!
Last modified 1yr ago