Posts

Showing posts from March, 2017

Change I2C Address SRF10

Change I2C Address of SRF10 Address Long Flash Short flashes Decimal Hex 224 E0 1 0 226 E2 1 1 228 E4 1 2 230 E6 1 3 232 E8 1 4 234 EA 1 5 236 EC 1 6 238 EE 1 7 240 F0 1 8 242 F2 1 9 244 F4 1 10 246 F6 1 11 248 F8 1 12 250 FA 1 13 252 FC 1 14 254 FE 1 15 Address Table For SRF10 can set ID for I2C up to 16 address as a table upper, So this post is about how to set ID for every SRF10. First, you need to have an only one SRF10 connect to I2C bus then use to the following code. Change Address Code: #include <Wire.h> #define ADDRESS byte(0x72) //defines address #define NEW_ADDRESS byte(0xEC) //defines address #define CMD byte(0x00) void setup() { // put your setup code here, to run once: Wire.begin(); //conects I2C Serial.begin(115200); } void loop() { // put your main code here, to run repeatedly: delay(5000); Serial.println("Begin"); Wire.beginTransmission(ADDRESS); Wire.write(CMD); Wire.write(byte(0xA0)); Wire.end

SRF10

Image
SRF10 Ultrasonic sensors SRF10 connector description This module used I2C as a protocol to communication with MCU. This module support to use with more than one module in system up to 16 module. We can set ID address for each module before integrated to the system, About how to change ID address click here . For distance to measure this module can measure from 6 cm to 6 m. Sample code: #include <Wire.h> //For Ultrasonic //ADDRESS #define Front_Left 112 #define Front_Right 114 #define CMD 0x00 #define Read_inch 0x50 #define Read_cen 0x51 #define Read_micro_sec 0x52 #define Read_pointer 0x02 void setup() { // put your setup code here, to run once: Serial.begin(115200); Wire.begin(); } void loop() { // put your main code here, to run repeatedly: //Correct Data Serial.println("----"); read_distance_ultrasonic(Front_Left); delay(75); read_distance_ultrasonic(Front_Right); delay(75); } int read_distance_ultrasonic(int addr){ i

VNH2SP30 Motor Driver Carrier MD01B

Image
VNH2SP30 Motor Driver Carrier MD01B VNH2SP30 Motor Driver Carrier MD01B connector description This module used for drive a DC motor. Pin that needs to connected is PWM, IN A, IN B, OUT A, OUT B, +5 V, and GND. Sample code: #define InA_PIN 4 //Yellow #define InB_PIN 5 //Blue #define PWM_PIN 3 //Green //INA 1 INB 0 clockwise FORWARD //INA 0 INB 1 counterclockwise REVERSE void setup() { // put your setup code here, to run once: pinMode(InA_PIN, OUTPUT); pinMode(InB_PIN, OUTPUT); pinMode(PWM_PIN, OUTPUT); analogWrite(PWM_PIN, 0); digitalWrite(InA_PIN, HIGH); digitalWrite(InB_PIN, LOW); } void loop() { // put your main code here, to run repeatedly: digitalWrite(InA_PIN, HIGH); digitalWrite(InB_PIN, LOW); analogWrite(PWM_PIN, 255); delay(2000); digitalWrite(InA_PIN, LOW); digitalWrite(InB_PIN, HIGH); analogWrite(PWM_PIN, 127); delay(5000); } If IN A is high and IN B is low then the motor will drive forward. But if IN A is low and IN B is

Sharp 2Y0A21 F 03

Image
Sharp 2Y0A21 F 03 Distance Measuring Sensor Unit Sharp 2Y0A21 F 03 This sensor can measure a distance from 10 to 80 cm with analog output. The range of output voltage is defined as a graph below. Voltage output from 0.4 to 2.25 V (80 to 10 cm) Sample Code: void setup() { // put your setup code here, to run once: pinMode(A6, INPUT); pinMode(A7, INPUT); Serial.begin(115200); } void loop() { // put your main code here, to run repeatedly: Serial.println(analogRead(A6)); delay(1); Serial.println(analogRead(A7)); delay(1000); } Because the output of this sensor in analog output, So we can read data easily by using ADC. (analogRead() function in arduino) In this code, we read from 2 sharp sensors and print output to a serial port. Reference:  Datasheet

Arduino Servo Library Test

Image
Servo Test RC Servo for steering RC cars In RC cars, It's already integrated with RC Servo that can move from 0 to 180 degrees. But actually it can move from 45 to 120 degrees for steering the angle is fix by gears. Sample code: #include <Servo.h> #define mins 45 //degree #define maxs 120 //degree #define center 83 //degree //Maximum speed for turn steering 10ms Servo myservo; int angle = center; bool left = true; void setup() { // put your setup code here, to run once: myservo.attach(9); } void loop() { // put your main code here, to run repeatedly: myservo.write(angle); if(left){ angle--; }else{ angle++; } if(angle == mins){ left = false; } if(angle == maxs){ left = true; } delay(15); } This code will move the servo continuous from left to right and right to left by the limit angle of steering. Reference:  Arduino Servo

CMPS03 Compass Module

Image
CMPS03 Compass Module CMPS03 connector description This module used I2C as a protocol to communicate with MCU and use 5V for power supply. Data from I2C is compass Bearing as a word, i.e. 0-3599 for a full circle, representing 0-359.9 degrees. Sample Code: /* CMPS03 with arduino I2C example This will display a value of 0 - 359 for a full rotation of the compass. The SDA line is on analog pin 4 of the arduino and is connected to pin 3 of the CMPS03. The SCL line is on analog pin 5 of the arduino and is conected to pin 2 of the CMPS03. Both SDA and SCL are also connected to the +5v via a couple of 1k8 resistors. A switch to callibrate the CMPS03 can be connected between pin 6 of the CMPS03 and the ground. */ #include <wire .h> #define ADDRESS 0x60 //defines address of compass void setup(){ Wire.begin(); //conects I2C Serial.begin(9600); } void loop(){ byte highByte; byte lowByte; Wire.beginTransmission(ADDRESS); //starts communication

Track Design

Image
Track Design Our track will separate to 2 parts. First, track for drive automatically around the track. Design track for drive automatically around the track Second, Track for drifting. Design track for drifting

RC Cars Equipment and Sensors

Image
Detail of our RC Cars A complete build of RC Cars: Front view of RC Cars Rear view of RC Cars List of Sensors and Equipment: SHARP 2Y0A21 F 03 CMPS03 SRF10 VNH2SP30 Motor Driver Carrier MD01B ET-MMA7331L HAL Sensors RC Servo DC Motors Arduino MEGA Raspberry Pi 2 Raspberry Pi Camera Battery Pack CMPS03 (Compass Module) Raspberry Pi Camera SHARP 2Y0A21 F 03 (Analog Infrared Distance Sensor) SRF10 (Ultrasonic Distance Sensor) ET-MMA7331L (Accelerometer) VNH2SP30 Motor Driver Carrier MD01B (DC Motor Driver) RC Servo, DC Motor, HAL Sensors Arduino MEGA Raspberry Pi 2 Battery Pack

About This Project & Criteria

Image
"Self-Drifting Cars" This Project has been proposed because of we want to do something for fun in course "Embedded System 2016" @SSE TGGS KMUTNB, Thailand. Inspiration : Here's a video to show that self-driving cars can be self-drifting cars too But to work on real cars, we don't have much funding then this project we will use RC cars instead of real cars. And this project will not be only a part of self-drifting cars we will have a telemetry system to show a status of our RC cars. e.g, Distance from sensors around the car, Video streaming from cars. Criteria: Phase 1 Without Drift Hot Lapse [20%] 3 Lapse within xx seconds. [5%] xx seconds [3%] xx seconds [1%] more than xx seconds [0%] Rules Collision avoidance (Not hit the wall and obstacle) [5%] (each collision -1%) Set speed close-loop control [10%] Speed +- 5% [Get 10%] Speed +-10%[Get 7%] Speed +-20%[Get 4%] Speed more than +-20%[Get 0%] Telem