can you adjust the buffers in the code below to match a 1306 Graphic Display Data RAM…
- User
can you adjust the buffers in the code below to match a 1306 Graphic Display Data RAM (GDDRAM) The GDDRAM is a bit mapped static RAM holding the bit pattern to be displayed. The size of the RAM is 128 x 64 bits and the RAM is divided into eight pages, from PAGE0 to PAGE7, which are used for monochrome 128x64 dot matrix display? : #include <Wire.h> #include <esp_now.h> #include <WiFi.h> #include <esp_wifi.h>
#define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define BUFFER_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 8)
#define I2C_DEV_ADDR 0x3C #define CHANNEL 1 //#define MAX_POSSIBLE_DATA_SIZE 256 // This should be the largest data size you ever expect
uint8_t dataBuffer[BUFFER_SIZE]; unsigned int bufferHead = 0; unsigned int bufferTail = 0; unsigned int currentDataSize = 0; // Current size of data received
//uint8_t dataArray[MAX_POSSIBLE_DATA_SIZE]; //uint8_t currentDataSize = 0; // Current size of data received
esp_now_peer_info_t slave; bool isSlavePaired = false; // Track if slave is currently paired
void onReceive(int len) { currentDataSize = len; for (int i = 0; i < len; i++) { addToBuffer(Wire.read()); } sendData(); for (int i = 0; i < BUFFER_SIZE; i++) { Serial.print(dataBuffer[i], HEX); Serial.print(" "); if ((i + 1) % 16 == 0) { // Print 16 values per line Serial.println(); } } }
void addToBuffer(uint8_t data) { bufferHead = (bufferHead + 1) % BUFFER_SIZE; // Wrap around if buffer is full dataBuffer[bufferHead] = data; if (bufferHead == bufferTail) { bufferTail = (bufferTail + 1) % BUFFER_SIZE; // Remove oldest data when buffer is full } }
void sendData() { const uint8_t* peer_addr = slave.peer_addr; esp_err_t result = esp_now_send(peer_addr, dataBuffer + bufferTail, currentDataSize);
if (result == ESP_OK) { Serial.println("Success"); } else { Serial.println("Send Error"); } }
void InitESPNow() { WiFi.disconnect();
codefor(int retries = 0; retries < 3; retries++) { if (esp_now_init() == ESP_OK) { Serial.println("ESPNow Init Success"); break; } else { if(retries == 2) { Serial.println("ESPNow Init Failed 3 times, restarting..."); delay(1000); ESP.restart(); } delay(500); } }}
bool manageSlave() { if (slave.channel == CHANNEL) { bool exists = esp_now_is_peer_exist(slave.peer_addr); if (exists) { Serial.println("Already Paired"); return true; } else { esp_err_t addStatus = esp_now_add_peer(&slave); if (addStatus == ESP_OK) { Serial.println("Pair success"); return true; } else { Serial.println("Pairing Error"); } } } else { Serial.println("No Slave found to process"); } return false; }
- Assistant
To adjust the buffers to match a 1306 Graphic Display Data RAM (GDDRAM) with a size of 128 x 64 bits, you need to change the BUFFER_SIZE constant to match the size of the GDDRAM. In this case, the BUFFER_SIZE should be 1024 bytes (128 x 64 / 8).
Replace the following line:
cpp#define BUFFER_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 8)With:
cpp#define BUFFER_SIZE 1024With this change, the buffer will be able to store the entire GDDRAM data.