microrobotics

Untitled

Aug 31st, 2018
1,485
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>          // * I2C Mode
  2. #define OLED_Address 0x3c
  3. #define OLED_Command_Mode 0x80
  4. #define OLED_Data_Mode 0x40
  5.  
  6. void setup()
  7. {
  8.   Wire.begin();
  9. }
  10.  
  11. void loop()
  12. {
  13.  
  14.  // * I2C initial * //
  15.  delay(100);
  16.  sendCommand(0x2A);    // ** Set "RE"=1    00101010B
  17.  sendCommand(0x71);
  18.  sendCommand(0x5C);
  19.  sendCommand(0x28);
  20.  
  21.  sendCommand(0x08);    // ** Set Sleep Mode On
  22.  sendCommand(0x2A);    // ** Set "RE"=1    00101010B
  23.  sendCommand(0x79);    // ** Set "SD"=1    01111001B
  24.  
  25.  sendCommand(0xD5);
  26.  sendCommand(0x70);
  27.  sendCommand(0x78);    // ** Set "SD"=0
  28.  
  29.  sendCommand(0x08);    // ** Set 5-dot, 3 or 4 line(0x09), 1 or 2 line(0x08)
  30.  
  31.  sendCommand(0x06);    // ** Set Com31->Com0  Seg0->Seg99
  32.  
  33.  // ** Set OLED Characterization * //
  34.  sendCommand(0x2A);      // ** Set "RE"=1
  35.  sendCommand(0x79);      // ** Set "SD"=1
  36.  
  37.  // ** CGROM/CGRAM Management * //
  38.  sendCommand(0x72);      // ** Set ROM
  39.  sendCommand(0x00);      // ** Set ROM A and 8 CGRAM
  40.  
  41.  sendCommand(0xDA);     // ** Set Seg Pins HW Config
  42.  sendCommand(0x10);  
  43.  
  44.  sendCommand(0x81);      // ** Set Contrast
  45.  sendCommand(0xFF);
  46.  
  47.  sendCommand(0xDB);      // ** Set VCOM deselect level
  48.  sendCommand(0x30);      // ** VCC x 0.83
  49.  
  50.  sendCommand(0xDC);      // ** Set gpio - turn EN for 15V generator on.
  51.  sendCommand(0x03);
  52.  
  53.  sendCommand(0x78);      // ** Exiting Set OLED Characterization
  54.  sendCommand(0x28);
  55.  sendCommand(0x2A);
  56.  //sendCommand(0x05);     // ** Set Entry Mode
  57.  sendCommand(0x06);     // ** Set Entry Mode
  58.  sendCommand(0x08);  
  59.  sendCommand(0x28);     // ** Set "IS"=0 , "RE" =0 //28
  60.  sendCommand(0x01);
  61.  sendCommand(0x80);     // ** Set DDRAM Address to 0x80 (line 1 start)
  62.  
  63.  delay(100);
  64.  sendCommand(0x0C);      // ** Turn on Display
  65.  
  66.  // ******************************************************************//
  67.  // ** Show Data Value * //
  68.  
  69.  
  70.  send_string("Micro Robotics");
  71.  sendCommand(0xC0);      // ** New Line
  72.  send_string("OLED Display");
  73.  
  74.  //sendCommand(0x01);    // ** Clear display
  75.  while(1);
  76.  
  77.  // ** Show Data Value * //
  78.  // ******************************************************************//
  79.  
  80. }
  81.  
  82. void sendData(unsigned char data)
  83. {
  84.     Wire.beginTransmission(OLED_Address);      // ** Start I2C
  85.     Wire.write(OLED_Data_Mode);             // ** Set OLED Data mode
  86.     Wire.write(data);
  87.     Wire.endTransmission();                     // ** End I2C
  88. }
  89.  
  90. void sendCommand(unsigned char command)
  91. {
  92.     Wire.beginTransmission(OLED_Address);      // ** Start I2C
  93.     Wire.write(OLED_Command_Mode);              // ** Set OLED Command mode
  94.     Wire.write(command);
  95.     Wire.endTransmission();                      // ** End I2C
  96.       delay(10);
  97. }
  98.  
  99. void send_string(const char *String)
  100. {
  101.     unsigned char i=0;
  102.     while(String[i])
  103.     {
  104.         sendData(String[i]);      // * Show String to OLED
  105.         i++;
  106.     }
  107. }
RAW Paste Data