module 2-4: writing our first programs akiba -freaklabs

12
Module 2-4: Writing Our First Programs Akiba - FreakLabs

Upload: others

Post on 17-May-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Module 2-4: Writing Our First Programs Akiba -FreakLabs

• Module 2-4: Writing Our First Programs

• Akiba - FreakLabs

Page 2: Module 2-4: Writing Our First Programs Akiba -FreakLabs

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

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

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

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

Writing the Code

Code continues on next page. …

Page 7: Module 2-4: Writing Our First Programs Akiba -FreakLabs

Writing the Code

Code continues on next page. …

Page 8: Module 2-4: Writing Our First Programs Akiba -FreakLabs

Writing the Code

Page 9: Module 2-4: Writing Our First Programs Akiba -FreakLabs

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

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

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

MODULE 3-5Reading and Writing to the SD card

Lab 5C: Did I Just Create a Data

Logger?