background image

33

1. Import the I2C and accelerometer libraries and create an instance of ADXL345 accelerometer.
2. Initialize serial monitor and ADXL345 accelerometer.
3. Read the accelerometer values of three axis and store them in variables.
4. Print the accelerometer values of three axis.
5. Get the accelerometer values of three axis in G units and print.

Code overview

Code usage

Import the library of ADXL345 accelerometer. The calculation of acceleration is relatively complicated. 
Fortunately, we can use the functions in this library to simplify the difficulty of using the accelerometer. 
The I2C address of the accelerometer has been defined in the library file, so we will not declare the 
I2C address of the accelerometer again in the program.

ADXL345 library: #include <ADXL345.h>

Sets the byte which holds the threshold value for detecting activity/inactivity. The data format is 
unsigned, so the magnitude of the activity/inactivity event is compared with the value is compared with 
the value in the THRESH_ACT/THRESH_INACT register. The scale factor is 62.5mg/LSB. A value of 
0 may result in undesirable behavior if the activity/inactivity interrupt is enabled. The maximum value 
is 255.

Activity and inactivity threshold: adxl.setActivityThreshold(75);      

adxl.setInactivityThreshold(75);

The function of reading the acceleration data from the ADXL345. We need to pass the address of 
three axis to this function. Each axis reading comes in 10-bit resolution, ie 2 bytes.  Least Significant 
Byte first!! Thus we are converting both bytes into one int.

Read acceleration data: adxl.readXYZ(&x, &y, &z);

Read the acceleration data in G unit. The parameters filled in the brackets are the arrays in which we 
need to store the accelerometers of the three axes read. The first, second and third elements of the 
array store the x-axis, y-axis and z Acceleration data.

Read acceleration in G unit: adxl.getAcceleration(xyz);

Summary of Contents for Crowtail Deluxe Kit

Page 1: ...www elecrow com 2020 ELECROW All Rights Reserved C User Guide V2 0 2020 02 Crowtail Deluxe Kit for Arduino...

Page 2: ...erature reminder Lesson 7 Colorful RGB light Lesson 8 Show text on OLED Lesson 9 Ultrasonic ranging display Lesson 10 Use of the joystick Lesson 11 Servo control Lesson 12 Smart door Lesson 13 IR cont...

Page 3: ...o build a smart car completely including wireless remote control intelligent tracking or obstacle avoidance etc Of course there are more complex move ment data acquisition wifi and Bluetooth use The C...

Page 4: ...mb Joystick x1 Crowtail IR Receiver x1 Crowtail IR Emitter x1 Crowtail Hall Sensor x1 Crowtail One Wire Waterproof Temperature Sensor x1 Crowtail Collision Sensor x1 Crowtail Ultrasonic Ranging Sensor...

Page 5: ...their own DIY mobile platform motor drive has always been a problem It need 2 DC motors at least to control their speed direction of rotation because you will want your platform forward turn back tur...

Page 6: ...used for UART communication such as the WIFI module or Bluetooth module 1 IIC ports A4 A5 that have a mark of I These interfaces are for the IIC Communication Besides there is also two motor connector...

Page 7: ...OW signal In fact it is very similar to the button except that the switch has a self locking function so that it can output logic high level signal without pressing it all the time In this lesson we a...

Page 8: ...ed as an output and switch as an input Digital Input We use the digitalRead function to read the value on a digital pin Check to see if an input pin is reading HIGH 5V or LOW 0V Returns TRUE 1 or FALS...

Page 9: ...mart car Lesson 2 Collision experiment Introduction Arduino Uno Crowduino Uno x1 Crowtail Motor Base Shield x1 Crowtail Collision Sensor x1 Crowtail LED x1 Crowtail Buzzer x1 Crowtail Cable x3 Require...

Page 10: ...iable First Macro defined constants cannot be changed while the program is running Variables can be changed Second the variable can be used inside the function defined by it but the life cycle end whe...

Page 11: ...l port monitor When you use the magnet s S polar to approach the hall sensor the red indicator light on the hall sensor will light up and the speed count will increase by one When you repeat the actio...

Page 12: ...rigger when change RISING low level to high level trigger FALLING high level to low level trigger We use a Hall sensor as the interrupt source connected to the D3 port When the interrupt occurs the S...

Page 13: ...which can drive two motors at the same time Of course a 4 wire stepper motor can also be driven After inserting the Crowtail Motor Base Shield into Arduino Crowduino the specific method of controllin...

Page 14: ...s way the car can turn right What will you see 1 Declare the pins to control the speed and direction of rotation of the two motors 2 Setup the pins which are used to control motors as output 3 Create...

Page 15: ...versa There is also an on board potentiometer to adjust the sensitivity This sensor is a basic and widely used part in applications such as line following cars rotary speed detection auto data logging...

Page 16: ...e three sensors are blocked by a black object the speed of motor1 and motor2 becomes 0 stopped What will you see 1 Declare the pins of three IR Reflective Sensors and variables to store the state of t...

Page 17: ...don t get any signal degradation even over long distances The DS18B20 provides 9 to 12 bit configurable temperature readings over a 1 Wire interface so that only one wire and ground needs to be conne...

Page 18: ...ibrary which is convenient for directly using temperature sensors such as DS18B20 Therefore using these two libraries it will be very convenient for us to use one wire waterproof temperature sensor Im...

Page 19: ...e RGB LED will light up in different colors like a rainbow What will you see The Crowtail RGB LED module with 4 pcs of WS2812B which is a Chainable Addressable LED Users can control all the LEDs with...

Page 20: ...lassic v1 not v2 FLORA pixels WS2811 drivers NEO_GRB Pixels are wired for GRB bitstream most NeoPixel products NEO_RGB Pixels are wired for RGB bitstream v1 FLORA pixels not v2 Create instance Adafrui...

Page 21: ...Call the function we created to show the Text Code overview Crowtail OLED is constructed from the 128 x 64 dot matrix OLED module The display offers high brightness self emission high contrast ratio s...

Page 22: ...tFont method to select the font we want to display and use the u8g drawStr method to set what position and character we want to draw There are three parameters in the u8g drawStr function The first pa...

Page 23: ...the libraries of ultrasonic ranging sensor and OLED 2 Create instances of ultrasonic ranging sensor and OLED 3 Create variables to store distance and characters array to change distance using charact...

Page 24: ...hat we want to create character related distance_ value_temp 5 0 means that we are creating an array that can contain 5 elements Since we used char to declare it it is 5 characters Finally we assign i...

Page 25: ...tick and store them in two variables 4 Print the x y axes value of joystick in decimal 5 Use if else statement to judge the direction of the joystick and print them Code overview they are actually two...

Page 26: ...e change in the value of the joystick after changing the position of the joystick So when you have a better idea you can change your value If Statements if logic statement code to be run if the logic...

Page 27: ...nd initialize it with 90 degrees 4 Read the joystick value 5 If the joystick button is pressed let the servo rotate to 90 degrees 6 If the joystick button is not pressed let the servo rotate to the co...

Page 28: ...rom fromLow to fromHigh it is also mapped to between toLow and toHigh in equal proportions So here we map the value of pos between 200 and 800 to angle between 0 and 180 For example if the value of jo...

Page 29: ...c ranging sensor and servo instance object so we can get the distance and make the servo rotate to the angle we want For ultrasonic object there are two parameters inside the parentheses we need to pa...

Page 30: ...appliance using an Arduino The Crowtail IR Receiver module uses the HS0038B which is miniaturized receivers for infrared remote control systems and it is the standard IR remote control receiver serie...

Page 31: ...essed for the second time the data LED2 is sent 7 If the collision sensor is pressed for the third time the data OFF is sent Infrared Receiver code 1 Import IR library and declare led buzzer and IR re...

Page 32: ...iver the data sent by the emitter we have to initialize the IR receiver to tell which pin to obtain the data Therefore we need to enter the pin of the receiver in the parentheses IR Receiver initializ...

Page 33: ...ta into the EEPROM 5 Call the reading function to read the data from the EEPROM and print Code overview Code usage Micro defines the I2C address of EEPROM The reason why I2C devices can be cascaded is...

Page 34: ...l change What will you see Arduino Uno Crowduino Uno x1 Crowtail Motor Base Shield x1 Crowtail 3 Axis Digital Accelerometer 16g x1 Crowtail Cable x1 Required Parts The Crowtail 3 Axis Digital Accelero...

Page 35: ...activity The data format is unsigned so the magnitude of the activity inactivity event is compared with the value is compared with the value in the THRESH_ACT THRESH_INACT register The scale factor is...

Page 36: ...you see Arduino Uno Crowduino Uno x1 Crowtail Motor Base Shield x1 Crowtail Analog Gyro x1 Crowtail Cable x1 Required Parts The Crowtail Analog Gyro is based on an angular velocity sensor Murata ENC...

Page 37: ...e float reference_Value 0 double angularVelocity To obtain the reference value is the reason why we need to calibrate the analog gyro in beginning We use for statement to get the analog gyro data 1000...

Page 38: ...plete connection is as follows Open the P17_Use_Of_Bluetooth with Arduino and upload it Extract the compressed package named HMPCComAssistant_en rar and open the serial port assistant software HMComAs...

Page 39: ...ived is 1 turn LED on Code overview Code usage Set the baud for serial monitor correspond to our bluetooth module 115200 is the default baud rate for our bluetooth module If we set the wrong baud for...

Page 40: ...a connector for 3 7V Lithium polymer batteries and built in battery charging You don t need a battery it will run just fine straight from the micro USB connector But if you do have a battery you can t...

Page 41: ...ferent you can check the port of the board in the port of your computer for Crowtail ESP8266 Node MCU and baud rate there After correctly set click the Connect option on the top of the menu 2 Connect...

Page 42: ...ck the button on the web page to turn LED and buzzer on or off Use overview Arduino Uno Crowduino Uno x1 Crowtail Motor Base Shield x1 Crowtail OLED x1 Crowtail Ultrasonic Ranging Sensor x1 Micro Spee...

Page 43: ...n t have to power Crowduino Arduino because the motor base shield will share the power with Crowduino Arduino Open the P19_A_Naughty_Robot with Arduino and upload it If there is nothing in front of th...

Page 44: ...8g_uint_t y u8g_uint_t w u8g_uint_t h const u8g_pgm_uint8_t bitmap x the abscissa of the upper left corner of the bitmap y the ordinate of the upper left corner of the bitmap w the width of the bitmap...

Page 45: ...the OUT3 and OUT4 interfaces are connected to the same motor positive and negative poles Be careful not to connect the motor to the interval interface such as OUT1 and OUT3 otherwise the motor will no...

Page 46: ...received 3 Setup all motor pins as output and initialize the IR receiver 4 Create some motor working functions to be called when different data is received 5 According to the received data the motor...

Page 47: ......

Reviews: