Programs
Raspberry Pi IoT in C Third Edition
We have decided not to make the programs available as a download because this is not the point of the book - the programs are not finished production code but something you should type in and study.
The best solution is to provide the source code of the programs in a form that can be copied and pasted into a VS Code project.
Note: The VS Code task listings are in Appendix II.
The only downside is that you have to create a project to paste the code into.
To do this follow the instructions in the book - in particular remember to add the bcm2835 library and also any library references that may be needed. The majority of the programs also need to be run with root permissions.
All of the programs below were copy and pasted from working programs in the IDE.
If anything you consider important is missing or if you have any requests or comments contact me
This email address is being protected from spambots. You need JavaScript enabled to view it.
Chapter 2
Page 28
Chapter 3
Page 47
Chapter 4
Page 50
Page 62
Page 64
Page 65
Page 66
Page 67
Page 68
Chapter 6
Page 89
Page 90
Page 91
Page 92
Page 93
Page 94
Page 97
Page 99
Page 100
Chapter 7
Page 111
Page 114
Page 116
Chapter 8
Page 122
Page 126
Page 127
Page 128
Page 129
Page 132
Page 137
page 140
Chapter 9
Page 151
Page 152
Page 153
Page 155
Page 156
Page 158
Page 159
Page 160
Page 163
Page 164
Page 166
Page 168
Chapter 10
Page 184
Page 186
Page 188
Page 192
Chapter 11
Page 203
Chapter 13
Page 223
Chapter 14
Page 233
Chapter 15
Page 246
function only - needs a main program to call it
Chapter 16
Page 268
On a Pi 5 serial0 opens the debug port. If you want to use GPIO14 and 15 use /dev/ttyAMA0 or any UART you have enabled.
#include <unistd.h>
#include <fcntl.h>
Page 268
On a Pi 5 serial0 opens the debug port. If you want to use GPIO14 and 15 use /dev/ttyAMA0 or any UART you have enabled.
This loopback most likely wont work unless the serial port is already configured - see next program.
Page 278
On a Pi 5 serial0 opens the debug port. If you want to use GPIO14 and 15 use /dev/ttyAMA0 or any UART you have enabled.
Page 279
On a Pi 5 serial0 opens the debug port. If you want to use GPIO14 and 15 use /dev/ttyAMA0 or any UART you have enabled.
Page 281
On a Pi 5 serial0 opens the debug port. If you want to use GPIO14 and 15 use /dev/ttyAMA0 or any UART you have enabled.
Page 287
On a Pi 5 serial0 opens the debug port. If you want to use GPIO14 and 15 use /dev/ttyAMA0 or any UART you have enabled.
Chapter 17
Page 303
Chapter 18
Page 312
Chapter 19
Page 324
Page 326
Page 331
Chapter 20
Page 350
Page 355
Page 360
Page 362
Page 370
Chapter 21
Page 372
Page 378
Chapter 22
Page 395
Page 399
Page 402
Appendix I
Page 406
Page 407
Appendix II
All files have to be stored in the .vscode folder
settings,json (typical)
launch.json
c_cpp_properties.json for Mingw
tasks.json
"showReuseMessage": true,
}
},
{
"label": "copyARMheaders",
"type": "shell",
"command": "mkdir ${workspaceFolder}/include/;scp -r ${config:sshUser}@${config:sshEndpoint}:/usr/include ${workspaceFolder}/include/ ",
"problemMatcher": [],
"presentation": {
"showReuseMessage": true,
"clear": true
}
},
],
}