do you think anyone could help me out im trying to get two esp32's with .96oled screens to talk esp now on one i am sending a analog value to the other one it should use that value to adjust a ds1841 digatal pot and display the value from one to a hunderd i have a code ive been working on i am sending the value to the other one but cant get it to display the value im new to ardunio but feel like i did ok on this one but need a little experience that i dont have yet thanks if any one could help
// Include Libraries
#include <esp_now.h>
#include <WiFi.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
const int analogValue = analogRead(34);
// Define variables to store incoming readings
int analogvalue = 0
//Define a data structure
typedef struct struct_message {
char a[32];
int b "send analogValue to myDate"
} struct_message;
// Create a structured object
struct_message myData;
// Callback function executed when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&myData, incomingData, sizeof(myData));
Serial.print("Data received: ");
Serial.println(len);
Serial.print("Character Value: ");
Serial.println(myData.a);
Serial.print("analogValue: ");
Serial.println(myData.b);
Serial.println();
}
void setup() {
//set the resolution to 12 bits (0-4096)
analogReadResolution(8);
// Set up Serial Monitor
Serial.begin(115200);
if (!display.begin(SSD1306 , 0x3C))
{
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
display.clearDisplay();
// Set ESP32 as a Wi-Fi Station
WiFi.mode(WIFI_STA);
NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Register callback function
esp_now_register_recv_cb(OnDataRecv);
}
void loop() {
// read the analog / millivolts value for pin 34:
int analogValue = analogRead(34);
int analogVolts = analogReadMilliVolts(34);
display.setTextColor(WHITE); display.clearDisplay();
display.setTextSize(2); display.setCursor(20,0); display.print("B3 Design");
display.setCursor(10,18); display.print("AnalogValue");
display.setTextSize(3); display.setCursor(25,42); display.print(myData.a,myData.b);
display.display();
}
I was looking at it on your other thread, and couldn't make sense of a part, and wonder if it even compiles, let alone running and doing what you want.
IMO...
The Adafruit OLED is just too clumbersome to start out with...
When working with displays, I always flesh-out the display routines first and add in other code.
#include <Wire.h>
#include "font.h"
#define OLED_address 0x3c // all the OLED's I have seen have this address
//#define offset 0x00 // SDD1306 // offset=0 for SSD1306 controller
#define offset 0x02 // SH1106 // offset=2 for SH1106 controller
//==========================================================//
// Resets display depending on the actual mode.
static void reset_display(void)
{
displayOff();
clear_display();
displayOn();
}
//==========================================================//
// Turns display on.
void displayOn(void)
{
sendcommand(0xaf); //display on
}
//==========================================================//
// Turns display off.
void displayOff(void)
{
sendcommand(0xae); //display off
}
//==========================================================//
// Clears the display by sendind 0 to all the screen map.
static void clear_display(void)
{
unsigned char i, k;
for (k = 0; k < 8; k++)
{
setXY(k, 0);
{
for (i = 0; i < (128 + 2 * offset); i++) //locate all COL
{
SendChar(0); //clear all COL
//delay(10);
}
}
}
}
//==========================================================//
// Actually this sends a byte, not a char to draw in the display.
// Display's chars uses 8 byte font the small ones and 96 bytes
// for the big number font.
static void SendChar(unsigned char data)
{
Wire.beginTransmission(OLED_address); // begin transmitting
Wire.write(0x40);//data mode
Wire.write(data);
Wire.endTransmission(); // stop transmitting
}
//==========================================================//
// Prints a display char (not just a byte) in coordinates X Y,
// being multiples of 8. This means we have 16 COLS (0-15)
// and 8 ROWS (0-7).
static void sendCharXY(unsigned char data, int X, int Y)
{
setXY(X, Y);
Wire.beginTransmission(OLED_address); // begin transmitting
Wire.write(0x40);//data mode
for (int i = 0; i < 8; i++)
Wire.write(pgm_read_byte(myFont[data - 0x20] + i));
Wire.endTransmission(); // stop transmitting
}
//==========================================================//
// Used to send commands to the display.
static void sendcommand(unsigned char com)
{
Wire.beginTransmission(OLED_address); //begin transmitting
Wire.write(0x80); //command mode
Wire.write(com);
Wire.endTransmission(); // stop transmitting
}
//==========================================================//
// Set the cursor position in a 16 COL * 8 ROW map.
static void setXY(unsigned char row, unsigned char col)
{
sendcommand(0xb0 + row); //set page address
sendcommand(offset + (8 * col & 0x0f)); //set low col address
sendcommand(0x10 + ((8 * col >> 4) & 0x0f)); //set high col address
}
//==========================================================//
// Prints a string regardless the cursor position.
static void sendStr(unsigned char *string)
{
unsigned char i = 0;
while (*string)
{
for (i = 0; i < 8; i++)
{
SendChar(pgm_read_byte(myFont[*string - 0x20] + i));
}
*string++;
}
}
//==========================================================//
// Prints a string in coordinates X Y, being multiples of 8.
// This means we have 16 COLS (0-15) and 8 ROWS (0-7).
static void sendStrXY( char *string, int X, int Y)
{
setXY(X, Y);
unsigned char i = 0;
while (*string)
{
for (i = 0; i < 8; i++)
{
SendChar(pgm_read_byte(myFont[*string - 0x20] + i));
}
*string++;
}
}
//==========================================================//
// Inits oled and draws logo at startup
static void init_OLED(void)
{
sendcommand(0xae); //display off
sendcommand(0xa6); //Set Normal Display (default)
// Adafruit Init sequence for 128x64 OLED module
sendcommand(0xAE); //DISPLAYOFF
sendcommand(0xD5); //SETDISPLAYCLOCKDIV
sendcommand(0x80); // the suggested ratio 0x80
sendcommand(0xA8); //SSD1306_SETMULTIPLEX
sendcommand(0x3F);
sendcommand(0xD3); //SETDISPLAYOFFSET
sendcommand(0x0); //no offset
sendcommand(0x40 | 0x0); //SETSTARTLINE
sendcommand(0x8D); //CHARGEPUMP
sendcommand(0x14);
sendcommand(0x20); //MEMORYMODE
sendcommand(0x00); //0x0 act like ks0108
//sendcommand(0xA0 | 0x1); //SEGREMAP //Rotate screen 180 deg
sendcommand(0xA0);
//sendcommand(0xC8); //COMSCANDEC Rotate screen 180 Deg
sendcommand(0xC0);
sendcommand(0xDA); //0xDA
sendcommand(0x12); //COMSCANDEC
sendcommand(0x81); //SETCONTRAS
sendcommand(0xCF); //
sendcommand(0xd9); //SETPRECHARGE
sendcommand(0xF1);
sendcommand(0xDB); //SETVCOMDETECT
sendcommand(0x40);
sendcommand(0xA4); //DISPLAYALLON_RESUME
sendcommand(0xA6); //NORMALDISPLAY
clear_display();
sendcommand(0x2e); // stop scroll
//----------------------------REVERSE comments----------------------------//
// Next 3 lines control display top-bottom or bottom-top MRB 20150718
sendcommand(0xa0); //seg re-map 0->127(default)
sendcommand(0xa1); //seg re-map 127->0
sendcommand(0xc8);
// delay(1000);
//----------------------------REVERSE comments----------------------------//
// sendcommand(0xa7); //Set Inverse Display
// sendcommand(0xae); //display off
sendcommand(0x20); //Set Memory Addressing Mode
sendcommand(0x00); //Set Memory Addressing Mode ab Horizontal addressing mode
// sendcommand(0x02); // Set Memory Addressing Mode ab Page addressing mode(RESET)
}
Above authored mostly by Dan see credits below:
/*
Modified, refactored & additions by Ray Burnette, July 2015
Arduino IDE 1.6.1
Sketch uses 246,665 bytes (47%) of program storage space.
Arduino 1.6.6
Sketch uses 248,088 bytes (47%) of program storage space. Maximum is 524,288 bytes.
=============================== OLED Connections =============================
OLED: http://www.aliexpress.com/item/Free-shipping-1Pcs-white-128X64-OLED-LCD-LED-Display-Module-For-Arduino-0-96-I2C-IIC/32234039563.html
Connections://Wire.pins(int sda, int scl) Wire.pins(0, 2); //on ESP-01.
==== ESP8266 Pin==== ==== OLED Pin====
Vcc 1 Vcc 1
Rxd 2
Rst 3
GPIO0 4 SDA 4 use 1.8K Ohm pullup
CH_PD 5
CPIO2 6 SCL 3 " ditto "
Txd 7
Gnd 8 Gnd 2
Credits:
DanBicks added OLED display to ESP01 using cheap Ebay 0.96" display
Lightweight OLED routines by Mike-Rankin added in this project
http://www.esp8266.com/viewtopic.php?f=29&t=3256
Original source: https://github.com/costonisp/ESP8266-I2C-OLED
OLED code supports either SDD1306 or with SH1106 controller
/Sketch uses 249,888 bytes (50%) of program storage space. Maximum is 499,696 bytes.
Global variables use 36,277 bytes (44%) of dynamic memory, leaving 45,643 bytes for local variables. Maximum is 81,920 bytes.
*/