SEM

Library functions



The Sensor.Engine MICRO library (installed in the SEM library flash) adds language elements to the BASIC language specific to the SEM.

SEM Startup
mm.startup is a function located in the library that will run before the main BASIC program runs in flash. For the SEM, mm.startup provides these functions:
1) Initialize the SEM LCD display.
2) Set up the SD card for access.
3) Print the banner text to the SEM display and to the serial console.
4) Get the Real Time Clock date and time, if the module is present.
5) Run AUTORUN.BAS from the root of the SD card, if the SD card and file exist.
6) Run SEM.BAS from the root of the SD card, if the SD card and file exist (and AUTORUN.BAS does not).


SEM Display initialization
SEM.initdisplay reinitializes the SEM display. If the display becomes corrupt or unresponsive in use then this SEM library routine will reset and clear the display.


Display driver
The library loaded into the SEM contains the driver needed to put text and graphics on the SEM's SSD1306 display.


SD card routines
The library contains the driver needed to read/write the SD card. This is a limited version of SD card capability requiring that the SD card contain placeholder/blank files of appropriate size prior to the SEM writing to the files. There is no "create" or "delete" of files or directories from the SEM.


SDload - Load BASIC program from SD card

SDload(filename$) will load a BASIC program from the SD card.

SDloadrun(filename$) will load a BASIC program from the SD card and immediately run it.

filename$ is the name of the basic file. Examples:

SDload("FRED.BAS") loads FRED.BAS from root directory

SDload("APPS/WILMA.BAS") loads WILMA.BAS from the APPS subdirectory


SDsave - Save BASIC program to the SD card

SDsave(filename$) will save a BASIC program to the SD card.

filename$ is the name of the basic file.


SDopen - Open a file on the SD card

SDopen(filename$) will setup the SEM to read from or write to a specific file. When an open is issued, the file position is reset - the first byte read using the SDread subroutine is the first byte of the file on the SD card.

filename$ can be a variable, such as x$, or a string literal such as “file.txt”.

SDopen will set the variable SEM.Path$ to the name of the directory or directory/subdirectory and the variable SEM.FileName$ from filename$. SDopen also resets the file position by resetting SEM.FilePos to 0.


SDread - Read string from a file on the SD card

SDread(s$, numbytes, offset) The operation of SDread applies to the file name opened by SDopen.

The string s$ will contain the bytes read from the file. The number of bytes to read is set by the integer numbytes (or 1, if the field is either left blank or set to 0).

Initially after opening the file, the data read comes from the beginning of the file. Subsequent reads come from the next unread location if offset is set to -1. offset can be used used to specify a starting location in the file for the read.

Bytes in the file start at an offset of 0. To read any specific place in the file, set offset to that byte location. If offset is set to a negative number the read position starts where the last read left off.

SDread needs to be set to an integer for the return value. In other words, the function should be assigned to an integer value when called in BASIC: n = SDread(s$) the integer n then contains 0 if the number of bytes that were read from the file is the same as the number requested. If the number of bytes read from the file is less than the number of bytes requested, then n contains the difference.

SDreadline - Read a CR/LF delimited line from a file on the SD card

SDreadline(s$, offset) The operation of SDreadline applies to the file name opened by SDopen.

The string s$ will contain the bytes read from the file up to the first linefeed or carriage return linefeed combination. The next SDreadline call will read the next CR/LF delimited line. SEM.FilePos is updated to the position after the CR/LF delimiter.


SDwrite - Write string to a file on the SD card

SDwrite(s$, numbytes, offset) The operation of SDwrite applies to the file name opened by SDopen.

The string s$ should contain the bytes intended to be written to the file. The number of bytes to write is set by the integer numbytes (or 1, if the field is either left blank or set to 0).

Initially after opening the file, the data written goes to the beginning of the file. Subsequent writes go to the next unwritten location if offset is set to -1. offset can be used used to specify a starting location in the file for the write.

SDwrite needs to be set to an integer for the return value. In other words, the function should be assigned to an integer value when called in BASIC: n = SDwrite(s$) the integer n then contains the number of bytes that were written to the file.


SDDIR - Get the directory of the SD card

SDDIR(dirname$)

SDDIR will set the variable SEM.Path$ to the name of the directory or directory/subdirectory from dirname$.

SEM.Path$ is null when in the root directory.


If you have more information about certain modules, please feel free to Contact us! and share what you know. If you also have test or application code to share, that link is the way to share that - we would appreciate your experiences and input a lot!

If you are interested in purchasing the unique devices that are shown on these pages,
CircuitGizmos (link: CircuitGizmosOnline) sells many of these devices. Also Tindie has several of the CircuitGizmos devices for sale.

If you have questions about sensor modules like these, consider joining the Facebook group.
Join the 37 Sensors FB Group! We'd love to see you there. If you are interested in the CircuitGizmos products, the FB page to join is CircuitGizmos on FB

Sometimes the 37 sensor projects are described as
Instructables. This is the Instructable user to follow: Indestructable and YouTube channel and even follow on Instagram. Link back to us, please! We really like learning how our products are used.

All content, not otherwise posted with a copyright notice, is Copyright 2017+ to the owner of 37sensors.com.