Advertisement
microrobotics

Adafruit DS2413 I2C Breakout

Apr 4th, 2023
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. To interface the Adafruit DS2413 I2C Breakout with an Arduino, you will need to install the "Adafruit DS2413" library. You can install it through the Arduino IDE by going to Sketch > Include Library > Manage Libraries, then search for "Adafruit DS2413" and install the library.
  3.  
  4. Here's an example code for interfacing the DS2413 I2C Breakout with an Arduino:
  5.  
  6. This code initializes the DS2413 I2C Breakout and configures the GPIO pins as outputs. It then toggles the GPIO pins every second.
  7.  
  8. Connect the DS2413 I2C Breakout to the Arduino as follows:
  9.  
  10. VCC to 5V (or 3.3V, depending on your sensor's voltage level)
  11. GND to GND
  12. SDA to the SDA pin on your Arduino (A4 on the Uno, Leonardo, or Nano; pin 20 on the Mega)
  13. SCL to the SCL pin on your Arduino (A5 on the Uno, Leonardo, or Nano; pin 21 on the Mega)
  14. Please note that different DS2413 modules might have slightly different pin arrangements, so verify the pin labels on your specific module before making connections.
  15. */
  16.  
  17. #include <Arduino.h>
  18. #include <Wire.h>
  19. #include <Adafruit_DS2413.h>
  20.  
  21. // Create an instance of the DS2413 sensor
  22. Adafruit_DS2413 ds2413;
  23.  
  24. void setup() {
  25.   Serial.begin(9600);
  26.   Wire.begin();
  27.  
  28.   if (!ds2413.begin()) {
  29.     Serial.println("Failed to find DS2413!");
  30.     while (1);
  31.   }
  32.   Serial.println("DS2413 found!");
  33.  
  34.   // Set the GPIO pins as outputs
  35.   ds2413.pinMode(DS2413_GPIOA, OUTPUT);
  36.   ds2413.pinMode(DS2413_GPIOB, OUTPUT);
  37. }
  38.  
  39. void loop() {
  40.   // Turn on GPIOA and turn off GPIOB
  41.   ds2413.digitalWrite(DS2413_GPIOA, HIGH);
  42.   ds2413.digitalWrite(DS2413_GPIOB, LOW);
  43.   delay(1000);
  44.  
  45.   // Turn off GPIOA and turn on GPIOB
  46.   ds2413.digitalWrite(DS2413_GPIOA, LOW);
  47.   ds2413.digitalWrite(DS2413_GPIOB, HIGH);
  48.   delay(1000);
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement