module 2-4: writing our first programs akiba -freaklabs
TRANSCRIPT
![Page 1: Module 2-4: Writing Our First Programs Akiba -FreakLabs](https://reader034.vdocuments.site/reader034/viewer/2022051813/628344728eb7173eb3623d15/html5/thumbnails/1.jpg)
• Module 2-4: Writing Our First Programs
• Akiba - FreakLabs
![Page 2: Module 2-4: Writing Our First Programs Akiba -FreakLabs](https://reader034.vdocuments.site/reader034/viewer/2022051813/628344728eb7173eb3623d15/html5/thumbnails/2.jpg)
MODULE 3-5Reading and Writing to the SD card
Lab 5B: Did I Just Create MS-DOS?
![Page 3: Module 2-4: Writing Our First Programs Akiba -FreakLabs](https://reader034.vdocuments.site/reader034/viewer/2022051813/628344728eb7173eb3623d15/html5/thumbnails/3.jpg)
Goals
• Create a command to write a sensor reading to a file
• Create a command to read the sensor reading from a file
• Create a command to delete a file
• Create a command to list out all the files in the directory
![Page 4: Module 2-4: Writing Our First Programs Akiba -FreakLabs](https://reader034.vdocuments.site/reader034/viewer/2022051813/628344728eb7173eb3623d15/html5/thumbnails/4.jpg)
Why Is This Important?
• Build more familiarity with the file system and file operations
• Quicker and easier to write, read and test our code through the command line
• Most important - test out critical part of our data logger functionality!
![Page 5: Module 2-4: Writing Our First Programs Akiba -FreakLabs](https://reader034.vdocuments.site/reader034/viewer/2022051813/628344728eb7173eb3623d15/html5/thumbnails/5.jpg)
What Do I Need to Know?
• myFile.write()
• myFile.read()
PLUS
• sd.ls()• Lists all the files in a directory
• sd.remove(filename)• Removes a file called filename from the sd card.
![Page 6: Module 2-4: Writing Our First Programs Akiba -FreakLabs](https://reader034.vdocuments.site/reader034/viewer/2022051813/628344728eb7173eb3623d15/html5/thumbnails/6.jpg)
Writing the Code
Code continues on next page. …
![Page 7: Module 2-4: Writing Our First Programs Akiba -FreakLabs](https://reader034.vdocuments.site/reader034/viewer/2022051813/628344728eb7173eb3623d15/html5/thumbnails/7.jpg)
Writing the Code
•
Code continues on next page. …
![Page 8: Module 2-4: Writing Our First Programs Akiba -FreakLabs](https://reader034.vdocuments.site/reader034/viewer/2022051813/628344728eb7173eb3623d15/html5/thumbnails/8.jpg)
Writing the Code
•
![Page 9: Module 2-4: Writing Our First Programs Akiba -FreakLabs](https://reader034.vdocuments.site/reader034/viewer/2022051813/628344728eb7173eb3623d15/html5/thumbnails/9.jpg)
Writing the Code
•
Don’t forget to check the new line is set to carriage return and the baud rate is 57600
![Page 10: Module 2-4: Writing Our First Programs Akiba -FreakLabs](https://reader034.vdocuments.site/reader034/viewer/2022051813/628344728eb7173eb3623d15/html5/thumbnails/10.jpg)
Writing the Code
• fwrite filename = writes a sensor reading to the specified file name
• fread filename = reads the data in the specified file
![Page 11: Module 2-4: Writing Our First Programs Akiba -FreakLabs](https://reader034.vdocuments.site/reader034/viewer/2022051813/628344728eb7173eb3623d15/html5/thumbnails/11.jpg)
Writing the Code
• ls = lists the files in the directory
• rm = deletes the specified file from the sd card
![Page 12: Module 2-4: Writing Our First Programs Akiba -FreakLabs](https://reader034.vdocuments.site/reader034/viewer/2022051813/628344728eb7173eb3623d15/html5/thumbnails/12.jpg)
MODULE 3-5Reading and Writing to the SD card
Lab 5C: Did I Just Create a Data
Logger?