\doxysection{spi\+\_\+basic.\+ino}
\hypertarget{spi__basic_8ino_source}{}\label{spi__basic_8ino_source}\index{examples/spi\_basic/spi\_basic.ino@{examples/spi\_basic/spi\_basic.ino}}
\mbox{\hyperlink{spi__basic_8ino}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00001}00001\ /***************************************************************}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00002}00002\ \ *\ @file\ \ \ \ SPI\_Basic.ino}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00003}00003\ \ *\ @brief\ \ \ Minimal\ SPI\ bring-\/up\ for\ 7Semi\ ICM-\/20948\ +}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00004}00004\ \ *\ \ \ \ \ \ \ \ \ \ basic\ Accel/Gyro/Temp\ readout\ (updated\ API).}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00005}00005\ \ *}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00006}00006\ \ *\ Features}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00007}00007\ \ *\ -\/\ SPI\ init\ (UNO\ /\ ESP32)}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00008}00008\ \ *\ -\/\ beginSPI()\ initialization}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00009}00009\ \ *\ -\/\ Manual\ sensor\ enable}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00010}00010\ \ *\ -\/\ Read\ Accel\ /\ Gyro\ /\ Temp}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00011}00011\ \ *}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00012}00012\ \ *\ Notes}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00013}00013\ \ *\ -\/\ WHO\_AM\_I\ must\ be\ 0xEA}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00014}00014\ \ *\ -\/\ Sensors\ must\ be\ explicitly\ enabled}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00015}00015\ \ *\ -\/\ SPI\ speed\ \string~1MHz\ recommended\ during\ init}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00016}00016\ \ *}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00017}00017\ \ *\ Wiring\ (Arduino\ UNO\ SPI)}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00018}00018\ \ *\ -\/\ SCK\ \ -\/>\ D13}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00019}00019\ \ *\ -\/\ MOSI\ -\/>\ D11}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00020}00020\ \ *\ -\/\ MISO\ -\/>\ D12}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00021}00021\ \ *\ -\/\ CS\ \ \ -\/>\ D10\ (changeable;\ update\ CS\_PIN)}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00022}00022\ \ *\ -\/\ VCC\ \ -\/>\ 3V3}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00023}00023\ \ *\ -\/\ GND\ \ -\/>\ GND}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00024}00024\ \ *}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00025}00025\ \ *\ Wiring\ (ESP32\ VSPI\ default)}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00026}00026\ \ *\ -\/\ SCK\ \ -\/>\ D13}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00027}00027\ \ *\ -\/\ MOSI\ -\/>\ D11}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00028}00028\ \ *\ -\/\ MISO\ -\/>\ D12}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00029}00029\ \ *\ -\/\ CS\ \ \ -\/>\ D10}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00030}00030\ \ ***************************************************************/}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00031}00031\ \#include\ <DevLab\_ICM20948.h>}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00032}00032\ }
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00033}00033\ /**\ @brief\ SPI\ clock\ used\ during\ sensor\ initialization\ and\ reads.\ */}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00034}00034\ \#define\ SPI\_FAST\_SPEED\ 1000000}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00035}00035\ }
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00036}00036\ /**\ @brief\ Global\ ICM-\/20948\ driver\ instance.\ */}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00037}00037\ DevLab\_ICM20948\ imu;}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00038}00038\ }
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00039}00039\ /**\ @brief\ SPI\ bus\ object\ used\ by\ the\ IMU\ driver.\ */}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00040}00040\ SPIClass\ spi\_bus(SPI);}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00041}00041\ }
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00042}00042\ /**}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00043}00043\ \ *\ @brief\ Initialize\ Serial\ and\ start\ the\ ICM-\/20948\ over\ SPI.}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00044}00044\ \ *}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00045}00045\ \ *\ @note\ The\ sketch\ expects\ a\ board-\/level\ CS\_PIN\ definition\ to\ select\ the}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00046}00046\ \ *\ chip-\/select\ pin\ used\ by\ beginSPI().}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00047}00047\ \ */}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00048}00048\ void\ setup()\ \{}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00049}00049\ \ \ Serial.begin(115200);}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00050}00050\ \ \ delay(200);}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00051}00051\ }
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00052}00052\ }
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00053}00053\ \ \ if\ (!imu.beginSPI(CS\_PIN,\ spi\_bus,\ 1000000))\ \{}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00054}00054\ \ \ \ \ Serial.println("{}ERROR:\ beginSPI()\ failed"{});}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00055}00055\ \ \ \ \ while\ (1)\ delay(200);}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00056}00056\ \ \ \}}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00057}00057\ }
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00058}00058\ \ \ imu.setSensors(true,\ true,\ true);}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00059}00059\ \ \ Serial.println("{}Ready."{});}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00060}00060\ \}}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00061}00061\ }
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00062}00062\ /**}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00063}00063\ \ *\ @brief\ Read\ and\ print\ accelerometer,\ gyroscope,\ and\ temperature\ data.}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00064}00064\ \ */}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00065}00065\ void\ loop()\ \{}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00066}00066\ \ \ float\ ax,\ ay,\ az;}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00067}00067\ \ \ float\ gx,\ gy,\ gz;}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00068}00068\ \ \ float\ tC;}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00069}00069\ }
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00070}00070\ \ \ /*\ Read\ accelerometer.\ */}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00071}00071\ \ \ if\ (imu.readAccel(ax,\ ay,\ az))\ \{}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00072}00072\ \ \ \ \ Serial.print(F("{}ACC\ [g]:\ "{}));}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00073}00073\ \ \ \ \ Serial.print(ax,\ 3);\ Serial.print("{},\ "{});}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00074}00074\ \ \ \ \ Serial.print(ay,\ 3);\ Serial.print("{},\ "{});}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00075}00075\ \ \ \ \ Serial.println(az,\ 3);}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00076}00076\ \ \ \}\ else\ \{}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00077}00077\ \ \ \ \ Serial.println(F("{}ACC\ read\ failed"{}));}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00078}00078\ \ \ \}}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00079}00079\ }
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00080}00080\ \ \ /*\ Read\ gyroscope.\ */}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00081}00081\ \ \ if\ (imu.readGyro(gx,\ gy,\ gz))\ \{}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00082}00082\ \ \ \ \ Serial.print(F("{}GYR\ [dps]:\ "{}));}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00083}00083\ \ \ \ \ Serial.print(gx,\ 2);\ Serial.print("{},\ "{});}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00084}00084\ \ \ \ \ Serial.print(gy,\ 2);\ Serial.print("{},\ "{});}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00085}00085\ \ \ \ \ Serial.println(gz,\ 2);}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00086}00086\ \ \ \}\ else\ \{}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00087}00087\ \ \ \ \ Serial.println(F("{}GYR\ read\ failed"{}));}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00088}00088\ \ \ \}}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00089}00089\ }
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00090}00090\ \ \ /*\ Read\ temperature.\ */}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00091}00091\ \ \ if\ (imu.readTemperature(tC))\ \{}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00092}00092\ \ \ \ \ Serial.print(F("{}TMP\ [C]:\ "{}));}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00093}00093\ \ \ \ \ Serial.println(tC,\ 2);}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00094}00094\ \ \ \}\ else\ \{}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00095}00095\ \ \ \ \ Serial.println(F("{}TMP\ read\ failed"{}));}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00096}00096\ \ \ \}}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00097}00097\ }
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00098}00098\ \ \ Serial.println(F("{}-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/"{}));}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00099}00099\ \ \ delay(500);}
\DoxyCodeLine{\Hypertarget{spi__basic_8ino_source_l00100}00100\ \}}

\end{DoxyCode}
