Arduino-ROS, example - Accelerometer ADXL 335

In this example, we are interfacing Accelerometer ADXL 335 to Arduino Mega through ADC pins and plotting the values using the ROS tool called rqt_plot.

The following image shows the circuit of the connection between ADLX 335 and Arduino:

Figure 11: Interfacing Arduino - ADXL 335

ADLX 335 is an analog accelerometer. We can simply connect to the ADC port and read the digital value. The following is the embedded code to interface ADLX 335 via Arduino ADC:

#if (ARDUINO >= 100) #include <Arduino.h> #else #include <WProgram.h> #endif #include <ros.h> #include <rosserial_arduino/Adc.h> const int xpin ...

Get Mastering ROS for Robotics Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.