Advertisement
Guest User

Roomba Blink

a guest
May 29th, 2015
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.77 KB | None | 0 0
  1. /*  Roomba Blink
  2.  
  3.     Sends an active low pulse to the DD (Device Detect) Pin of the Roomba 4000
  4.     for 500msec to wake the Roomba up from the default power on sleep state
  5.    
  6.     Puts the Roomba in Full Command Mode, turn off safety features
  7.     ignore wheel drops, cliff detectors and connected charger
  8.  
  9.         Initializes a software defined serial port
  10.         on pins 5 and 6 of the Arduino Uno
  11.    
  12.     Illuminates the Roomba Power and Status LED
  13.         Green for two seconds, then Red for one second, repeatedly
  14.        
  15.     Flashes the Arduino Uno built in LED connected to Digital Pin 13
  16.         On for two seconds, then Off for two seconds, repeatedly
  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.   digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  62.   greenStatusOn();      // turn the Roomba Power and Status LED Green
  63.   delay(2000);              // wait for two seconds
  64.   digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  65.   redStatusOn();        // turn the Roomba Power and Status LED Red
  66.   delay(1000);              // wait for a second
  67. }
  68.  
  69. void greenStatusOn() {
  70.   mySerial.write(139);       // control LEDs opcode
  71.   mySerial.write(32);        // Status On Green 00100000 Binary = 32 Decimal
  72.   mySerial.write((byte)0);   // Power Color Green
  73.   mySerial.write(255);       // Intensity set to full
  74. }
  75.  
  76. void redStatusOn() {
  77.   mySerial.write(139);        // control LEDs opcode
  78.   mySerial.write(16);         // Status On Green 00010000 Binary = 16 Decimal
  79.   mySerial.write(255);        // Power Color Red
  80.   mySerial.write(255);        // Intensity set to full
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement