Arducar – RC Car with wifi

November 9th, 2009 in
Arduino | tags: Arduino, dc motor, motorshield, rc car, servo, wishield |
3 Comments




After about 2 houres of soldering everything works well
Now i can control my servo & dc motor with ease
#include <servotimer1 .h> ServoTimer1 servo1; ServoTimer1 servo2; void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Servo test!"); servo1.attach(10); servo2.attach(9); } void loop() { Serial.print("tick"); servo1.write(180); servo2.write(0); delay(1000); Serial.print("tock"); servo1.write(0); servo2.write(180); delay(1000); } </servotimer1>
With the Arduino app you can control a led matrix over wifi on your iphone.
Later you can save your “icon” and load older ones.
Sourcecode is still a bit clunky. But it Works
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); if(isOn) { [color setFill]; } else { [[UIColor grayColor] setFill]; } CGContextSetLineWidth(context, 1.0); CGContextAddEllipseInRect(context, rect); CGContextDrawPath(context, kCGPathFillStroke); }
Today i ported the mac ArduinoControll app to my iPhone.
+ now you can controll the LED via the UIAccelerometer
#pragma mark UIAccelerometer delegate - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { double xAcceleration = 100.0 - (acceleration.x + 1.0) * 100.0; double yAcceleration = 100.0 - (acceleration.y + 1.0) * 100.0; double zAcceleration = 100.0 - (acceleration.z + 1.0) * 100.0; accelerationX.text = [[NSString alloc] initWithFormat:@"%4.1f%", xAcceleration]; accelerationY.text = [[NSString alloc] initWithFormat:@"%4.1f%", yAcceleration]; accelerationZ.text = [[NSString alloc] initWithFormat:@"%4.1f%", zAcceleration]; long xValue = map(xAcceleration, -100, 100, 0, 7); long yValue = map(yAcceleration, -100, 100, 0, 7); [positionX setValue:xValue]; [positionY setValue:yValue]; NSString *command = [NSString stringWithFormat:@"SET LED %d:%d:%d", (int)xValue, (int)yValue, (int)[color value]]; [socket sendData:command]; }
Sourcecode of Arduino Controlling with iPhone
socketapp.c
extern char buffer[20]; static int handle_connection(struct socket_app_state *s) { PSOCK_BEGIN(&s->p); PSOCK_READTO(&s->p, '\n'); memcpy(buffer,s->inputbuffer,20); memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer)); PSOCK_END(&s->p); }
main
void loop() { WiFi.run(); if(strncmp(buffer, "SET LED", 7) == 0) { substr(positionX, buffer, 8,1); substr(positionY, buffer, 10,1); substr(color, buffer, 12,3); matrix.set(atoi(positionX),atoi(positionY), atoi(color)); matrix.send(); }
Sending to the socket server (Cocoa, NSStream)
-(void)sendData:(NSString *)string { NSString *stringWithEnding = [NSString stringWithFormat:@"%@\n", string]; const uint8_t * rawstring = (const uint8_t *)[stringWithEnding UTF8String]; [oStream write:rawstring maxLength:strlen(rawstring)]; }
Sourcecode of the Arduino Socket Server
Sourcecode of the Cocoa Socket Client
led matrix protocol:
SET LED x:y:color