{"id":3653,"date":"2023-10-07T05:31:16","date_gmt":"2023-10-07T12:31:16","guid":{"rendered":"https:\/\/www.donluc.com\/?p=3653"},"modified":"2023-10-07T05:31:16","modified_gmt":"2023-10-07T12:31:16","slug":"project-28-sensors-gyroscope-l3g4200d-mk03","status":"publish","type":"post","link":"https:\/\/www.donluc.com\/?p=3653","title":{"rendered":"Project #28 &#8211; Sensors &#8211; Gyroscope L3G4200D &#8211; Mk03"},"content":{"rendered":"<div style=\"width: 720px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-3653-1\" width=\"720\" height=\"480\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04W.mp4?_=1\" \/><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04W.mp4\">https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04W.mp4<\/a><\/video><\/div>\n<p>&#8212;&#8212;<\/p>\n<p>#DonLucElectronics #DonLuc #Sensors #L3G4200D #HMC5883L #ADXL335 #Adafruit #SparkFun #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant<\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04a.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04a.png\" alt=\"Gyroscope L3G4200D\" width=\"720\" height=\"577\" class=\"alignnone size-full wp-image-3655\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04a.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04a-300x240.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04b.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04b.png\" alt=\"Gyroscope L3G4200D\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-3656\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04b.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04b-300x200.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04c.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04c.png\" alt=\"Gyroscope L3G4200D\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-3657\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04c.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2023\/10\/DL2308Mk04c-300x200.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><strong>SparkFun Tri-Axis Gyroscope &#8211; L3G4200D<\/strong><\/p>\n<p>This is a breakout board for the L3G4200D low-power three-axis angular rate sensor. The L3G4200D is a MEMS motion sensor and has a full scale of dps and is capable of measuring rates with a user-selectable bandwidth. These work great in gaming and virtual reality input devices, motion control with MMI, GPS navigation systems, appliances and robotics. The L3G4200D is a low-power three-axis angular rate sensor able to provide unprecedented stablility of zero rate level and sensitivity over temperature and time. It includes a sensing element and an IC interface capable of providing the measured angular rate to the external world through a digital interface.<\/p>\n<p><strong>DL2308Mk04<\/strong><\/p>\n<p>1 x Adafruit METRO M0 Express<br \/>\n1 x DS3231 Precision RTC FeatherWing<br \/>\n1 x SparkFun Triple Axis Accelerometer ADXL335<br \/>\n1 x SparkFun Triple Axis Magnetometer &#8211; HMC5883L<br \/>\n1 x SparkFun Tri-Axis Gyroscope &#8211; L3G4200D<br \/>\n1 x Rocker Switch &#8211; SPST<br \/>\n1 x Resistor 10K Ohm<br \/>\n1 x CR1220 3V Lithium Coin Cell Battery<br \/>\n1 x SparkFun Cerberus USB Cable<\/p>\n<p><strong>Adafruit METRO M0 Express<\/strong><\/p>\n<p>LED &#8211; LED_BUILTIN<br \/>\nSDA &#8211; Digital 20<br \/>\nSCL &#8211; Digital 21<br \/>\nSW1 &#8211; Digital 2<br \/>\nACX &#8211; Analog A0<br \/>\nACY &#8211; Analog A1<br \/>\nACZ &#8211; Analog A2<br \/>\nVIN &#8211; +3.3V<br \/>\nGND &#8211; GND<\/p>\n<p>&#8212;&#8212;<\/p>\n<p><strong>DL2308Mk04p.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/****** Don Luc Electronics \u00a9 ******\r\nSoftware Version Information\r\nProject #28 - Sensors - Gyroscope L3G4200D - Mk03\r\n28-03\r\nDL2308Mk04p.ino\r\n1 x Adafruit METRO M0 Express\r\n1 x DS3231 Precision RTC FeatherWing\r\n1 x SparkFun Triple Axis Accelerometer ADXL335\r\n1 x SparkFun Tri-Axis Gyroscope - L3G4200D\r\n1 x Rocker Switch - SPST\r\n1 x Resistor 10K Ohm\r\n1 x CR1220 3V Lithium Coin Cell Battery\r\n1 x SparkFun Cerberus USB Cable\r\n*\/\r\n\r\n\/\/ Include the Library Code\r\n\/\/ DS3231 Precision RTC \r\n#include &lt;RTClib.h&gt;\r\n\/\/ Two Wire Interface (TWI\/I2C)\r\n#include &lt;Wire.h&gt;\r\n\/\/ Keyboard\r\n#include &lt;Keyboard.h&gt;\r\n\/\/ Triple Axis Magnetometer\r\n#include &lt;HMC5883L.h&gt;\r\n\/\/ Gyroscope\r\n#include &lt;L3G4200D.h&gt;\r\n\r\n\/\/ Keyboard\r\nString sKeyboard = &quot;&quot;;\r\n\r\n\/\/ DS3231 Precision RTC \r\nRTC_DS3231 rtc;\r\nString dateRTC = &quot;&quot;;\r\nString timeRTC = &quot;&quot;;\r\n\r\n\/\/ Accelerometer\r\nint iX = A0;\r\nint iY = A1;\r\nint iZ = A2;\r\n\/\/ Accelerometer\r\nint X = 0;\r\nint Y = 0;\r\nint Z = 0;\r\n\r\n\/\/ Triple Axis Magnetometer\r\nHMC5883L compass;\r\n\/\/ Triple Axis Magnetometer\r\nint mX = 0;\r\nint mY = 0;\r\nint mZ = 0;\r\n\r\n\/\/ Gyroscope\r\nL3G4200D gyroscope;\r\n\/\/ Timers\r\nunsigned long timer = 0;\r\nfloat timeStep = 0.01;\r\n\/\/ Pitch, Roll and Yaw values\r\nfloat pitch = 0;\r\nfloat roll = 0;\r\nfloat yaw = 0;\r\n\r\n\/\/ The number of the pushbutton pin\r\nint iButton = 2;\r\n\/\/ Variable for reading the button status\r\nint buttonState = 0;\r\n\r\n\/\/ Software Version Information\r\nString sver = &quot;28-03&quot;;\r\n\r\nvoid loop() {\r\n\r\n  \/\/ Date and Time RTC\r\n  isRTC ();\r\n\r\n  \/\/ Accelerometer\r\n  isAccelerometer();\r\n\r\n  \/\/ Magnetometer\r\n  isMagnetometer();\r\n\r\n  \/\/ Gyroscope\r\n  isGyroscope();\r\n\r\n  \/\/ Read the state of the button value:\r\n  buttonState = digitalRead(iButton);\r\n\r\n  \/\/ Check if the button is pressed. If it is, the buttonState is HIGH:\r\n  if (buttonState == HIGH) {\r\n\r\n     Keyboard.println(sKeyboard);\r\n    \r\n  }\r\n\r\n  \/\/ Delay 1 Second\r\n  delay(1000);\r\n\r\n}\r\n<\/pre>\n<p><strong>getAccelerometer.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ Accelerometer\r\n\/\/ Accelerometer\r\nvoid isAccelerometer(){\r\n\r\n  \/\/ Accelerometer X, Y, Z\r\n  \/\/ X\r\n  X = analogRead(iX);\r\n  \/\/ Y\r\n  Y = analogRead(iY);\r\n  \/\/ Z\r\n  Z = analogRead(iZ);\r\n\r\n  sKeyboard = sKeyboard + String(X) + &quot;|&quot; + String(Y) + &quot;|&quot; + String(Z) + &quot;|&quot;;\r\n\r\n}\r\n<\/pre>\n<p><strong>getGyroscope.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ L3G4200D Triple Axis Gyroscope\r\n\/\/ Setup Gyroscope\r\nvoid isSetupGyroscope() {\r\n\r\n  \/\/ Setup Gyroscope\r\n  \/\/ Set scale 2000 dps and 400HZ Output data rate (cut-off 50)\r\n  while(!gyroscope.begin(L3G4200D_SCALE_2000DPS, L3G4200D_DATARATE_400HZ_50))\r\n  {\r\n    \/\/ Could not find a valid L3G4200D sensor, check wiring!\r\n    delay(500);\r\n    \r\n  }\r\n\r\n  \/\/ Calibrate gyroscope. The calibration must be at rest.\r\n  \/\/ If you don&#039;t want calibrate, comment this line.\r\n  gyroscope.calibrate(100);\r\n  \r\n}\r\n\/\/ L3G4200D Gyroscope\r\nvoid isGyroscope(){\r\n\r\n  \/\/ Timer\r\n  timer = millis();\r\n\r\n  \/\/ Read normalized values\r\n  Vector norm = gyroscope.readNormalize();\r\n\r\n  \/\/ Calculate Pitch, Roll and Yaw\r\n  pitch = pitch + norm.YAxis * timeStep;\r\n  roll = roll + norm.XAxis * timeStep;\r\n  yaw = yaw + norm.ZAxis * timeStep;\r\n\r\n  sKeyboard = sKeyboard + String(pitch) + &quot;|&quot; + String(roll) + &quot;|&quot; + String(yaw) + &quot;|*&quot;;\r\n\r\n}\r\n<\/pre>\n<p><strong>getMagnetometer.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ Magnetometer\r\n\/\/ Setup Magnetometer\r\nvoid isSetupMagnetometer(){\r\n\r\n  \/\/ Magnetometer Serial\r\n  \/\/ Initialize HMC5883L\r\n  while (!compass.begin())\r\n  {\r\n    delay(500);\r\n  }\r\n\r\n  \/\/ Set measurement range\r\n  \/\/ +\/- 1.30 Ga: HMC5883L_RANGE_1_3GA (default)\r\n  compass.setRange(HMC5883L_RANGE_1_3GA);\r\n\r\n  \/\/ Set measurement mode\r\n  \/\/ Continuous-Measurement: HMC5883L_CONTINOUS (default)\r\n  compass.setMeasurementMode(HMC5883L_CONTINOUS);\r\n \r\n  \/\/ Set data rate\r\n  \/\/ 15.00Hz: HMC5883L_DATARATE_15HZ (default)\r\n  compass.setDataRate(HMC5883L_DATARATE_15HZ);\r\n\r\n  \/\/ Set number of samples averaged\r\n  \/\/ 1 sample:  HMC5883L_SAMPLES_1 (default)\r\n  compass.setSamples(HMC5883L_SAMPLES_1);\r\n  \r\n}\r\n\/\/ Magnetometer\r\nvoid isMagnetometer(){\r\n\r\n  \/\/ Vector Norm\r\n  Vector norm = compass.readNormalize();\r\n  \/\/ Vector X, Y, Z\r\n  \/\/ X Normalize\r\n  mX = norm.XAxis;\r\n  \/\/ Y Normalize\r\n  mY = norm.YAxis;\r\n  \/\/ Z Normalize\r\n  mZ = norm.ZAxis;\r\n\r\n  sKeyboard = sKeyboard + String(mX) + &quot;|&quot; + String(mY) + &quot;|&quot; + String(mZ) + &quot;|&quot;;\r\n\r\n}\r\n<\/pre>\n<p><strong>getRTC.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ Date &amp; Time\r\n\/\/ DS3231 Precision RTC\r\nvoid setupRTC() {\r\n\r\n  \/\/ DS3231 Precision RTC\r\n  if (! rtc.begin()) {\r\n    \/\/Serial.println(&quot;Couldn&#039;t find RTC&quot;);\r\n    \/\/Serial.flush();\r\n    while (1) delay(10);\r\n  }\r\n\r\n  if (rtc.lostPower()) {\r\n    \/\/Serial.println(&quot;RTC lost power, let&#039;s set the time!&quot;);\r\n    \/\/ When time needs to be set on a new device, or after a power loss, the\r\n    \/\/ following line sets the RTC to the date &amp; time this sketch was compiled\r\n    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));\r\n    \/\/ This line sets the RTC with an explicit date &amp; time, for example to set\r\n    \/\/ January 21, 2014 at 3am you would call:\r\n    \/\/rtc.adjust(DateTime(2023, 8, 10, 11, 0, 0));\r\n  }\r\n  \r\n}\r\n\/\/ Date and Time RTC\r\nvoid isRTC () {\r\n\r\n  \/\/ Date and Time\r\n  dateRTC = &quot;&quot;;\r\n  timeRTC = &quot;&quot;;\r\n  DateTime now = rtc.now();\r\n  \r\n  \/\/ Date\r\n  dateRTC = now.year(), DEC; \r\n  dateRTC = dateRTC + &quot;\/&quot;;\r\n  dateRTC = dateRTC + now.month(), DEC;\r\n  dateRTC = dateRTC + &quot;\/&quot;;\r\n  dateRTC = dateRTC + now.day(), DEC;\r\n\r\n  \/\/ Time\r\n  timeRTC = now.hour(), DEC;\r\n  timeRTC = timeRTC + &quot;:&quot;;\r\n  timeRTC = timeRTC + now.minute(), DEC;\r\n  timeRTC = timeRTC + &quot;:&quot;;\r\n  timeRTC = timeRTC + now.second(), DEC;\r\n\r\n  sKeyboard = &quot;SEN|&quot; + sver + &quot;|&quot; + String(dateRTC) + &quot;|&quot; + \r\n  String(timeRTC) + &quot;|&quot;;\r\n  \r\n}\r\n<\/pre>\n<p><strong>setup.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ Setup\r\nvoid setup()\r\n{\r\n  \r\n  \/\/ Give display time to power on\r\n  delay(100);\r\n  \r\n  \/\/ Wire - Inialize I2C Hardware\r\n  Wire.begin();\r\n\r\n  \/\/ Give display time to power on\r\n  delay(100);\r\n\r\n  \/\/ Date &amp; Time RTC\r\n  \/\/ DS3231 Precision RTC \r\n  setupRTC();\r\n  \r\n  \/\/ Initialize control over the keyboard:\r\n  Keyboard.begin();\r\n\r\n  \/\/ Setup Triple Axis Magnetometer\r\n  isSetupMagnetometer();\r\n\r\n  \/\/ L3G4200D Gyroscope\r\n  isSetupGyroscope();\r\n\r\n  \/\/ Initialize the button pin as an input\r\n  pinMode(iButton, INPUT);\r\n\r\n  \/\/ Initialize digital pin LED_BUILTIN as an output\r\n  pinMode(LED_BUILTIN, OUTPUT);\r\n  \/\/ Turn the LED on HIGH\r\n  digitalWrite(LED_BUILTIN, HIGH);\r\n\r\n  \/\/ Delay 5 Second\r\n  delay( 5000 );\r\n\r\n}\r\n<\/pre>\n<p>&#8212;&#8212;<\/p>\n<p><strong>People can contact us:<\/strong> https:\/\/www.donluc.com\/?page_id=1927<\/p>\n<p><strong>Technology Experience<\/strong><\/p>\n<ul>\n<li>Programming Language<\/li>\n<li>Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc&#8230;)<\/li>\n<li>IoT<\/li>\n<li>Wireless (Radio Frequency, Bluetooth, WiFi, Etc&#8230;)<\/li>\n<li>Robotics<\/li>\n<li>Camera and Video Capture Receiver Stationary, Wheel\/Tank and Underwater Vehicle<\/li>\n<li>Unmanned Vehicles Terrestrial and Marine<\/li>\n<li>Machine Learning<\/li>\n<li>RTOS<\/li>\n<li>Research &#038; Development (R &#038; D)<\/li>\n<\/ul>\n<p><strong>Instructor, E-Mentor, STEAM, and Arts-Based Training<\/strong><\/p>\n<ul>\n<li>Programming Language<\/li>\n<li>IoT<\/li>\n<li>PIC Microcontrollers<\/li>\n<li>Arduino<\/li>\n<li>Raspberry Pi<\/li>\n<li>Espressif<\/li>\n<li>Robotics<\/li>\n<\/ul>\n<p><strong>Follow Us<\/strong><\/p>\n<p><strong>Luc Paquin \u2013 Curriculum Vitae &#8211; 2023<\/strong><br \/>\nhttps:\/\/www.donluc.com\/luc\/<\/p>\n<p><strong>Web:<\/strong> https:\/\/www.donluc.com\/<br \/>\n<strong>Facebook:<\/strong> https:\/\/www.facebook.com\/neosteam.labs.9\/<br \/>\n<strong>YouTube:<\/strong> https:\/\/www.youtube.com\/@thesass2063<br \/>\n<strong>Twitter:<\/strong> https:\/\/twitter.com\/labs_steam<br \/>\n<strong>Pinterest:<\/strong> https:\/\/www.pinterest.com\/NeoSteamLabs\/<br \/>\n<strong>Instagram:<\/strong> https:\/\/www.instagram.com\/neosteamlabs\/<\/p>\n<p><strong>Don Luc<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8212;&#8212; #DonLucElectronics #DonLuc #Sensors #L3G4200D #HMC5883L #ADXL335 #Adafruit #SparkFun #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; SparkFun Tri-Axis Gyroscope &#8211; L3G4200D This is a breakout board for the L3G4200D low-power three-axis angular rate sensor. The L3G4200D is a MEMS motion sensor and has a full scale of dps and is capable &#8230; <a title=\"Project #28 &#8211; Sensors &#8211; Gyroscope L3G4200D &#8211; Mk03\" class=\"read-more\" href=\"https:\/\/www.donluc.com\/?p=3653\" aria-label=\"Read more about Project #28 &#8211; Sensors &#8211; Gyroscope L3G4200D &#8211; Mk03\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[294,47,50,49,38,59,5,287,58,10,43],"tags":[251,86,6,102,4,19,85,252,302,246,24,9,27,248,109,34,108],"class_list":["post-3653","post","type-post","status-publish","format-standard","hentry","category-sensors","category-adafruit","category-arduino","category-consultant","category-digitalelectronics","category-fritzing","category-microcontrollers","category-program","category-arduino-programming","category-projects","category-sparkfun","tag-accelerometer","tag-adafruit","tag-arduino","tag-components","tag-consultant","tag-electronics","tag-fritzing","tag-gyroscope","tag-gyroscope-l3g4200d","tag-magnetometer","tag-microcontroller","tag-programming","tag-projects-2","tag-sensors","tag-sparkfun","tag-video-blog","tag-vlog"],"_links":{"self":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3653"}],"version-history":[{"count":2,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3653\/revisions"}],"predecessor-version":[{"id":3961,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3653\/revisions\/3961"}],"wp:attachment":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}