Advertisement
Guest User

Arduino Roomba Blink Challenge 2

a guest
May 30th, 2015
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.17 KB | None | 0 0
  1. /*  Roomba Blink - Challenge 2
  2.  
  3.         by Justin Modra, follow my on Twitter @JustinModra
  4.         May 30, 2015
  5.        
  6.     Sends an active low pulse to the DD (Device Detect) Pin of the Roomba 4000
  7.     for 500msec to wake the Roomba up from the default power on sleep state
  8.    
  9.     Puts the Roomba in Full Command Mode, turn off safety features
  10.     ignore wheel drops, cliff detectors and connected charger
  11.  
  12.         Initializes a software defined serial port
  13.         on pins 5 and 6 of the Arduino Uno
  14.    
  15.     Illuminates the Roomba Power LED
  16.         Color fades through the possible color values from 0 to 255
  17.        
  18.     Roomba Serial Command Interface Specification at the following location:
  19.     http://www.ecsl.cs.sunysb.edu/mint/Roomba_SCI_Spec_Manual.pdf
  20.  
  21.     ArduinoUno Digital IO 5 RX to Roomba pin 4 TXD (yellow wire)
  22.     ArduinoUno Digital IO 6 TX to Roomba pin 3 RXD (orange wire)
  23.     ArduinoUno Digital IO 7 DD to Roomba pin 5 DD  (black wire)
  24.  
  25.         See the project description at the following website:
  26.         https://nightskylife.wordpress.com/2015/05/26/interfacing-roomba-model-4000-with-arduino-uno/
  27.  
  28. */
  29.  
  30. #include <SoftwareSerial.h>
  31. SoftwareSerial mySerial(5, 6); //rx,tx
  32. int ddPin = 7;
  33.  
  34.  
  35. // the setup function runs once when you press reset or power the board
  36. void setup() {
  37.   pinMode(ddPin,  OUTPUT);
  38.   pinMode(13, OUTPUT);
  39.   mySerial.begin(57600);
  40.   //Use Device Detect to wake Roomba
  41.   digitalWrite(ddPin, HIGH);
  42.   delay(100);
  43.   digitalWrite(ddPin, LOW);
  44.   delay(500);
  45.   digitalWrite(ddPin, HIGH);
  46.   delay(2000);
  47.   //Initialize Roomba SCI
  48.   // Start SCI
  49.   mySerial.write(128);
  50.   delay(100);
  51.   // Enable control
  52.   mySerial.write(130);  
  53.   delay(100);
  54.   // Enable full control, no safety, all commands
  55.   mySerial.write(132);
  56.   delay(100);
  57. }
  58.  
  59. // the loop function runs over and over again forever
  60. void loop() {
  61.    
  62.   for (int fadecount=0; fadecount < 256; fadecount++) {
  63.       mySerial.write(139);                   // control LEDs opcode
  64.       mySerial.write((byte)0);               // Status LED off
  65.       mySerial.write((byte)fadecount);       // Power Color
  66.       mySerial.write(255);               // Intensity set to full
  67.  
  68.       delay(100);
  69.   }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement