\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}}
\doxymbox{\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\ \#define\ SPI\_FAST\_SPEED\ 1000000}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00034}00034\ }
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00035}00035\ /**\ IMU\ inst0ance\ */}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00036}00036\ DevLab\_ICM20948\ imu;}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00037}00037\ }
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00038}00038\ SPIClass\ spi\_bus(SPI);\ \ \ //\ ←\ usa\ el\ bus\ SPI\ por\ defecto\ del\ Arduino}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00039}00039\ }
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00040}00040\ void\ setup()\ \{}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00041}00041\ \ \ Serial.begin(115200);}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00042}00042\ \ \ delay(200);}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00043}00043\ }
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00044}00044\ }
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00045}00045\ \ \ if\ (!imu.beginSPI(CS\_PIN,\ spi\_bus,\ 1000000))\ \{}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00046}00046\ \ \ \ \ Serial.println("{}ERROR:\ beginSPI()\ failed"{});}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00047}00047\ \ \ \ \ while\ (1)\ delay(200);}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00048}00048\ \ \ \}}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00049}00049\ }
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00050}00050\ \ \ imu.setSensors(true,\ true,\ true);}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00051}00051\ \ \ Serial.println("{}Ready."{});}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00052}00052\ \}}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00053}00053\ }
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00054}00054\ void\ loop()\ \{}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00055}00055\ \ \ float\ ax,\ ay,\ az;}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00056}00056\ \ \ float\ gx,\ gy,\ gz;}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00057}00057\ \ \ float\ tC;}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00058}00058\ }
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00059}00059\ \ \ /**\ Read\ Accelerometer\ */}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00060}00060\ \ \ if\ (imu.readAccel(ax,\ ay,\ az))\ \{}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00061}00061\ \ \ \ \ Serial.print(F("{}ACC\ [g]:\ "{}));}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00062}00062\ \ \ \ \ Serial.print(ax,\ 3);\ Serial.print("{},\ "{});}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00063}00063\ \ \ \ \ Serial.print(ay,\ 3);\ Serial.print("{},\ "{});}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00064}00064\ \ \ \ \ Serial.println(az,\ 3);}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00065}00065\ \ \ \}\ else\ \{}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00066}00066\ \ \ \ \ Serial.println(F("{}ACC\ read\ failed"{}));}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00067}00067\ \ \ \}}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00068}00068\ }
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00069}00069\ \ \ /**\ Read\ Gyroscope\ */}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00070}00070\ \ \ if\ (imu.readGyro(gx,\ gy,\ gz))\ \{}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00071}00071\ \ \ \ \ Serial.print(F("{}GYR\ [dps]:\ "{}));}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00072}00072\ \ \ \ \ Serial.print(gx,\ 2);\ Serial.print("{},\ "{});}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00073}00073\ \ \ \ \ Serial.print(gy,\ 2);\ Serial.print("{},\ "{});}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00074}00074\ \ \ \ \ Serial.println(gz,\ 2);}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00075}00075\ \ \ \}\ else\ \{}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00076}00076\ \ \ \ \ Serial.println(F("{}GYR\ read\ failed"{}));}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00077}00077\ \ \ \}}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00078}00078\ }
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00079}00079\ \ \ /**\ Read\ Temperature\ */}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00080}00080\ \ \ if\ (imu.readTemperature(tC))\ \{}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00081}00081\ \ \ \ \ Serial.print(F("{}TMP\ [C]:\ "{}));}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00082}00082\ \ \ \ \ Serial.println(tC,\ 2);}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00083}00083\ \ \ \}\ else\ \{}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00084}00084\ \ \ \ \ Serial.println(F("{}TMP\ read\ failed"{}));}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00085}00085\ \ \ \}}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00086}00086\ }
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00087}00087\ \ \ Serial.println(F("{}-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/"{}));}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00088}00088\ \ \ delay(500);}
\DoxyCodeLine{\Hypertarget{SPI__Basic_8ino_source_l00089}00089\ \}}

\end{DoxyCode}
