I need some help with CRC calculation. I spent a week trying to understand how a CRC (or Checksum) is calculated on a communication protocol
I have a Endress+Hauser pH probe (CPS11D-7FA21) that has MemoSense connector. Basically it is a digital pH probe. The communication is RS485 but the protocol is proprietary, so no info on that.
I connected the probe to a meter and sniffed the frames. There is a lot of data going back and fourth in the beginning but the polling repeats.
I was able to write some code for an Arduino and it worked, I can initialize the probe and pool measurements (ph(mV) and temperature), but the problem is that it only work with one probe. If I connect a new one it all stops.
I was digging a bit and I found out that right before the pooling starts the Init frame is different... Ii seem the measuring device somehow calculates the Init data from some other data that is exchanged in the beginning.
Anyway the fist thing is that I want to understand how the data frame is constructed.
Here is an example of pooling one of the probes and the data changes slightly
0x01, 0x01, 0x00, 0x00, 0x00, 0x2e, 0x04, 0x03, 0x09, 0x00, 0x20, 0xb9
0x01, 0x01, 0x00, 0x00, 0x00, 0x2f, 0x04, 0x03, 0x09, 0x00, 0x21, 0x99
0x01, 0x01, 0x00, 0x00, 0x00, 0x30, 0x04, 0x03, 0x09, 0x00, 0x3e, 0x7a
0x01, 0x01, 0x00, 0x00, 0x00, 0x32, 0x04, 0x03, 0x09, 0x00, 0x3c, 0x3a
0x01, 0x01, 0x00, 0x00, 0x00, 0x33, 0x04, 0x03, 0x09, 0x00, 0x3d, 0x1a
| <-------------------> | \ / \ / | | |
Header pH(mV)/10 Temp/100 ? Csum CRC???
0x01, 0x01, 0x00, 0x00, 0x00, 0x8d, 0x06, 0xf4, 0x08, 0x00, 0x77, 0x56
0x01, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x06, 0xf4, 0x08, 0x00, 0x75, 0x16
0x01, 0x01, 0x00, 0x00, 0x00, 0x88, 0x06, 0xf4, 0x08, 0x00, 0x72, 0xf6
0x01, 0x01, 0x00, 0x00, 0x00, 0x94, 0x06, 0xf5, 0x08, 0x00, 0x6f, 0x7d
0x01, 0x09, 0x04, 0x00, 0x0c, 0x00, 0x14, 0x02, 0x03, 0x11, 0x36, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x20, 0x20, 0x20, 0x20, 0x46, 0x57
0x01, 0x09, 0x04, 0x00, 0x0c, 0x00, 0x15, 0x07, 0x17, 0x12, 0x26, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x20, 0x20, 0x20, 0x20, 0x45, 0xb0
0x01, 0x00, 0x04, 0x00, 0x05, 0xa8, 0x4b, 0x53, 0x47, 0x31, 0x20, 0x01, 0x01, 0x01, 0x5a, 0x02, 0x9f, 0x27, 0x40, 0x39, 0x3f, 0x04, 0x52, 0x31, 0x32, 0x38, 0x44, 0x46, 0x30, 0x35, 0x42, 0x30, 0x33, 0x14, 0x01, 0x16, 0x00, 0x69, 0x00
0x01, 0x00, 0x04, 0x00, 0x05, 0xa8, 0x4b, 0x53, 0x47, 0x31, 0x20, 0x01, 0x01, 0x01, 0x01, 0x00, 0x75, 0x27, 0x41, 0xb8, 0x41, 0x04, 0x53, 0x36, 0x33, 0x37, 0x45, 0x44, 0x30, 0x35, 0x42, 0x30, 0x37, 0x15, 0x07, 0x06, 0x00, 0x3c, 0xf3
0x01, 0x08, 0x04, 0x00, 0x0d, 0xb0, 0xe5, 0x69, 0x1b, 0x00, 0x00, 0x69, 0x1b, 0x15, 0x07, 0x17, 0x12, 0x26, 0x02, 0x44, 0x1b, 0xaa, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x20, 0x20, 0x20, 0x20, 0xe9, 0xcd
0x01, 0x08, 0x04, 0x00, 0x0d, 0x40, 0xe7, 0x58, 0x1b, 0x00, 0x00, 0x67, 0x1b, 0x14, 0x02, 0x03, 0x11, 0x36, 0x02, 0x44, 0x1b, 0xaa, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x20, 0x20, 0x20, 0x20, 0x27, 0xde
Here is what I learned so far, the Csum is a standard 8bit Xor checksum
that works here
https://www.scadacore.com/tools/programming-calculators/online-checksum-calculator/
But the CRC is a mystery for me ... I tried multiple calculator and different data pieces and nothing. To me it seems it is a CRC because the if one bit changes there is a huge difference in the CRC byte
Maybe someone here could shed some light on this
Thank you
The last byte appears to be an exclusive-or and rotate check on the non-header bytes. If the message with check values is the unsigned char array a[0..len-1], then this computes the last two check values, x == a[len - 2] and y == a[len - 1]:
unsigned x = 0, y = 0;
for (size_t i = 0; i < len - 2; i++)
x ^= a[i];
for (size_t i = 5; i < len - 2; i++) {
y = (y ^ a[i]) << 1;
if (y & 0x100)
y ^= 0x101;
}
I am using a Arduino UNO with a c-control programmable graphic display.
I used the documentation of Franzis Maker Kit Grafikdisplays programmieren TURN ON YOUR CREATIVITY .
Display: DXDCG12864-4330 Displaycontroller: ST7564
My code is:
#include "TextDisplay.h"
int i=1;
TextDisplay display = TextDisplay();
void setup() {
display.init(25);
}
void loop() {
char buffer[40];
display.clear();
display.println("ABCD");
sprintf(buffer, " Dw2: %05d", i);
display.println(buffer);
delay(2000);
i++;
}
The problem is that the lines get printed beneath each other and that the display.clear() doesn't clean the display. The display shows after 2 loops:
ABCD
Dw2: 1
ABCD
Dw2: 2
instant of :
ABCD
Dw2: 2
TextDisplay.h:
#ifndef _TEXTDISPLAY_H_
#define _TEXTDISPLAY_H_
#include "Display.h"
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class TextDisplay {
public:
TextDisplay() {};
void init(byte contrast);
void println(const char* string);
void print(const char string);
void clear(void);
byte getLastCharPosition(byte line);
void writeTextBuffer();
private:
Display lcd;
byte textBuffer[8][22];
byte curserPositionY, curserPositionX;
};
#endif
TextDisplay.cpp:
#include "TextDisplay.h"
#include "Display.h"
#include "Font.h"
void TextDisplay::init(byte contrast) {
lcd = Display();
lcd.init(contrast);
lcd.clearDisplayRAM();
lcd.setPageAddress(0);
lcd.setColumnAddress(0);
curserPositionY = 0;
curserPositionX = 0;
textBuffer[MAX_CHARACTERS_Y][MAX_CHARACTERS_X];
}
void TextDisplay::println(const char* string) {
int position = 0;
while (string[position]) {
char character = string[position];
print(character);
string++;
}
print(13);
}
void TextDisplay::clear(void) {
print(255);
}
void TextDisplay::print(char character) {
switch (character) {
case 255:
for (byte y=0; y<MAX_CHARACTERS_Y; y++) {
for (byte x=0; x<MAX_CHARACTERS_X; x++) {
textBuffer[y][x] = 0;
}
}
writeTextBuffer();
curserPositionY = 0;
curserPositionX = 0;
break;
case 127: //Delete (Putty Backspace)
if (curserPositionX == 0 && curserPositionY > 0) {
curserPositionY--;
curserPositionX = getLastCharPosition(curserPositionY);
textBuffer[curserPositionY][curserPositionX] = 0;
}
else if (curserPositionX > 0) {
curserPositionX--;
textBuffer[curserPositionY][curserPositionX] = 0;
}
else {
}
break;
case 13: //CR
if (curserPositionY < MAX_CHARACTERS_Y-1) {
curserPositionY++;
curserPositionX = 0;
}
break;
default:
if (curserPositionX < MAX_CHARACTERS_X) {
textBuffer[curserPositionY][curserPositionX] = character;
curserPositionX++;
}
else if (curserPositionY < MAX_CHARACTERS_Y-1) {
curserPositionY++;
curserPositionX = 0;
textBuffer[curserPositionY][curserPositionX] = character;
curserPositionX++;
}
break;
}
writeTextBuffer();
}
byte TextDisplay::getLastCharPosition(byte line) {
for (byte x=0; x<MAX_CHARACTERS_X; x++) {
if(textBuffer[line][x] == 0) {
return (x!=0) ? x : 0;
}
}
return MAX_CHARACTERS_X-1;
}
void TextDisplay::writeTextBuffer() {
for (byte y=0; y<MAX_CHARACTERS_Y; y++) {
lcd.setPageAddress(y);
lcd.setColumnAddress(0);
for (byte x=0; x<MAX_CHARACTERS_X; x++) {
int position = textBuffer[y][x] * CHARACTER_WIDTH;
for (byte i=0; i<CHARACTER_WIDTH; i++) {
lcd.writeData(pgm_read_byte(font7x5 + position++));
}
}
}
}
Font.h:
#define CHARACTER_WIDTH 6
#define MAX_CHARACTERS_X 22
#define MAX_CHARACTERS_Y 8
const PROGMEM byte font7x5[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char NULL
0x3E, 0x55, 0x51, 0x55, 0x3E, 0x00, // Code for char
0x3E, 0x6B, 0x6F, 0x6B, 0x3E, 0x00, // Code for char
0x0E, 0x1F, 0x3E, 0x1F, 0x0E, 0x00, // Code for char
0x08, 0x1C, 0x3E, 0x1C, 0x08, 0x00, // Code for char
0x98, 0x9B, 0xFF, 0x9B, 0x98, 0x00, // Code for char
0x18, 0x5E, 0x7F, 0x5E, 0x18, 0x00, // Code for char
0x00, 0x08, 0x1C, 0x08, 0x00, 0x00, // Code for char
0x7F, 0x77, 0x63, 0x77, 0x7F, 0x00, // Code for char
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x30, 0x48, 0x48, 0x3E, 0x07, 0x00, // Code for char
0x06, 0x29, 0x79, 0x29, 0x06, 0x00, // Code for char
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x60, 0x7E, 0x06, 0x33, 0x3F, 0x00, // Code for char
0x49, 0x3E, 0x63, 0x3E, 0x49, 0x00, // Code for char
0x08, 0x08, 0x7F, 0x08, 0x08, 0x00, // Code for char
0x08, 0x1C, 0x3E, 0x7F, 0x00, 0x00, // Code for char
0x14, 0x22, 0x7F, 0x22, 0x14, 0x00, // Code for char
0x00, 0x5F, 0x00, 0x5F, 0x00, 0x00, // Code for char
0x06, 0x0F, 0x7F, 0x00, 0x7F, 0x00, // Code for char
0x08, 0x08, 0x0F, 0x08, 0x08, 0x00, // Code for char
0x08, 0x08, 0x78, 0x08, 0x08, 0x00, // Code for char
0x00, 0x08, 0x08, 0x7F, 0x00, 0x00, // Code for char
0x04, 0x02, 0x7F, 0x02, 0x04, 0x00, // Code for char
0x00, 0x7F, 0x08, 0x08, 0x00, 0x00, // Code for char
0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, // Code for char
0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00, // Code for char
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, // Code for char !
0x00, 0x03, 0x00, 0x03, 0x00, 0x00, // Code for char "
0x74, 0x1C, 0x77, 0x1C, 0x17, 0x00, // Code for char #
0x24, 0x4A, 0xFF, 0x52, 0x24, 0x00, // Code for char $
0x43, 0x33, 0x08, 0x66, 0x61, 0x00, // Code for char %
0x36, 0x49, 0x55, 0x22, 0x50, 0x00, // Code for char &
0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // Code for char '
0x00, 0x00, 0x3E, 0x41, 0x00, 0x00, // Code for char (
0x00, 0x00, 0x41, 0x3E, 0x00, 0x00, // Code for char )
0x00, 0x0A, 0x04, 0x0A, 0x00, 0x00, // Code for char *
0x00, 0x08, 0x1C, 0x08, 0x00, 0x00, // Code for char +
0x00, 0x00, 0xA0, 0x60, 0x00, 0x00, // Code for char ,
0x00, 0x08, 0x08, 0x08, 0x00, 0x00, // Code for char -
0x00, 0x00, 0x60, 0x60, 0x00, 0x00, // Code for char .
0x00, 0x60, 0x1C, 0x03, 0x00, 0x00, // Code for char /
0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, // Code for char 0
0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, // Code for char 1
0x42, 0x61, 0x51, 0x49, 0x46, 0x00, // Code for char 2
0x22, 0x41, 0x49, 0x49, 0x36, 0x00, // Code for char 3
0x1C, 0x13, 0x10, 0x78, 0x10, 0x00, // Code for char 4
0x4F, 0x49, 0x49, 0x49, 0x31, 0x00, // Code for char 5
0x3E, 0x49, 0x49, 0x49, 0x32, 0x00, // Code for char 6
0x01, 0x01, 0x71, 0x09, 0x07, 0x00, // Code for char 7
0x36, 0x49, 0x49, 0x49, 0x36, 0x00, // Code for char 8
0x26, 0x49, 0x49, 0x49, 0x3E, 0x00, // Code for char 9
0x00, 0x00, 0x6C, 0x6C, 0x00, 0x00, // Code for char :
0x00, 0x00, 0xAC, 0x6C, 0x00, 0x00, // Code for char ;
0x00, 0x08, 0x14, 0x22, 0x00, 0x00, // Code for char <
0x00, 0x14, 0x14, 0x14, 0x00, 0x00, // Code for char =
0x00, 0x22, 0x14, 0x08, 0x00, 0x00, // Code for char >
0x02, 0x01, 0x51, 0x09, 0x06, 0x00, // Code for char ?
0x3E, 0x5D, 0x5D, 0x51, 0x5E, 0x00, // Code for char #
0x7E, 0x09, 0x09, 0x09, 0x7E, 0x00, // Code for char A
0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, // Code for char B
0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, // Code for char C
0x7F, 0x41, 0x41, 0x22, 0x1C, 0x00, // Code for char D
0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, // Code for char E
0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, // Code for char F
0x3E, 0x41, 0x41, 0x51, 0x32, 0x00, // Code for char G
0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, // Code for char H
0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, // Code for char I
0x00, 0x20, 0x40, 0x3F, 0x00, 0x00, // Code for char J
0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, // Code for char K
0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, // Code for char L
0x7F, 0x02, 0x0C, 0x02, 0x7F, 0x00, // Code for char M
0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, // Code for char N
0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, // Code for char O
0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, // Code for char P
0x3E, 0x41, 0x41, 0x21, 0x5E, 0x00, // Code for char Q
0x7F, 0x09, 0x09, 0x09, 0x76, 0x00, // Code for char R
0x26, 0x49, 0x49, 0x49, 0x32, 0x00, // Code for char S
0x01, 0x01, 0x7F, 0x01, 0x01, 0x00, // Code for char T
0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, // Code for char U
0x03, 0x1C, 0x60, 0x1C, 0x03, 0x00, // Code for char V
0x1F, 0x60, 0x18, 0x60, 0x1F, 0x00, // Code for char W
0x63, 0x14, 0x08, 0x14, 0x63, 0x00, // Code for char X
0x03, 0x04, 0x78, 0x04, 0x03, 0x00, // Code for char Y
0x61, 0x51, 0x49, 0x45, 0x43, 0x00, // Code for char Z
0x00, 0x00, 0x7F, 0x41, 0x41, 0x00, // Code for char [
0x00, 0x03, 0x1C, 0x60, 0x00, 0x00, // Code for char BackSlash
0x00, 0x41, 0x41, 0x7F, 0x00, 0x00, // Code for char ]
0x00, 0x06, 0x01, 0x06, 0x00, 0x00, // Code for char ^
0x40, 0x40, 0x40, 0x40, 0x40, 0x00, // Code for char _
0x00, 0x00, 0x01, 0x02, 0x00, 0x00, // Code for char `
0x38, 0x44, 0x44, 0x44, 0x7C, 0x00, // Code for char a
0x7F, 0x44, 0x44, 0x44, 0x38, 0x00, // Code for char b
0x38, 0x44, 0x44, 0x44, 0x28, 0x00, // Code for char c
0x38, 0x44, 0x44, 0x44, 0x7F, 0x00, // Code for char d
0x38, 0x54, 0x54, 0x54, 0x58, 0x00, // Code for char e
0x00, 0x04, 0x7E, 0x05, 0x00, 0x00, // Code for char f
0x18, 0xA4, 0xA4, 0xA4, 0x7C, 0x00, // Code for char g
0x7F, 0x04, 0x04, 0x04, 0x78, 0x00, // Code for char h
0x00, 0x00, 0x7D, 0x00, 0x00, 0x00, // Code for char i
0x00, 0x40, 0x3D, 0x00, 0x00, 0x00, // Code for char j
0x7F, 0x20, 0x10, 0x28, 0x44, 0x00, // Code for char k
0x00, 0x00, 0x3F, 0x40, 0x00, 0x00, // Code for char l
0x78, 0x04, 0x78, 0x04, 0x78, 0x00, // Code for char m
0x04, 0x78, 0x04, 0x04, 0x78, 0x00, // Code for char n
0x38, 0x44, 0x44, 0x44, 0x38, 0x00, // Code for char o
0xF8, 0x44, 0x44, 0x44, 0x38, 0x00, // Code for char p
0x38, 0x44, 0x44, 0x44, 0xF8, 0x00, // Code for char q
0x00, 0x7C, 0x08, 0x04, 0x04, 0x00, // Code for char r
0x48, 0x54, 0x54, 0x54, 0x24, 0x00, // Code for char s
0x00, 0x04, 0x3F, 0x44, 0x00, 0x00, // Code for char t
0x3C, 0x40, 0x40, 0x40, 0x7C, 0x00, // Code for char u
0x0C, 0x30, 0x40, 0x30, 0x0C, 0x00, // Code for char v
0x1C, 0x60, 0x1C, 0x60, 0x1C, 0x00, // Code for char w
0x44, 0x28, 0x10, 0x28, 0x44, 0x00, // Code for char x
0x44, 0x48, 0x30, 0x08, 0x04, 0x00, // Code for char y
0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, // Code for char z
0x00, 0x08, 0x36, 0x41, 0x00, 0x00, // Code for char {
0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, // Code for char |
0x00, 0x41, 0x36, 0x08, 0x00, 0x00, // Code for char }
0x08, 0x04, 0x08, 0x08, 0x04, 0x00, // Code for char ~
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x14, 0x3E, 0x55, 0x55, 0x41, 0x00, // Code for char €
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x00, 0x00, 0xA0, 0x60, 0x00, 0x00, // Code for char ‚
0x00, 0x84, 0x7E, 0x05, 0x01, 0x00, // Code for char ƒ
0xA0, 0x60, 0x00, 0xA0, 0x60, 0x00, // Code for char „
0x40, 0x00, 0x40, 0x00, 0x40, 0x00, // Code for char …
0x04, 0x04, 0xFF, 0x04, 0x04, 0x00, // Code for char †
0x24, 0x24, 0xFF, 0x24, 0x24, 0x00, // Code for char ‡
0x00, 0x02, 0x01, 0x02, 0x00, 0x00, // Code for char ˆ
0x63, 0x13, 0x6C, 0x63, 0x60, 0x60, // Code for char ‰
0x48, 0x55, 0x56, 0x55, 0x24, 0x00, // Code for char Š
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ‹
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Œ
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ž
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ‘
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ’
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char “
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ”
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char •
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char –
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char —
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ˜
0x01, 0x07, 0x01, 0x07, 0x03, 0x07, // Code for char ™
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char š
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ›
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char œ
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ž
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ÿ
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ¡
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ¢
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char £
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ¤
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ¥
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ¦
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char §
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ¨
0x7E, 0x81, 0xBD, 0xA5, 0x81, 0x7E, // Code for char ©
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ª
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char «
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ¬
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char
0x7E, 0x81, 0xBD, 0x9D, 0xA1, 0x7E, // Code for char ®
0x01, 0x01, 0x01, 0x01, 0x01, 0x00, // Code for char ¯
0x00, 0x02, 0x05, 0x02, 0x00, 0x00, // Code for char °
0x00, 0x48, 0x5C, 0x48, 0x00, 0x00, // Code for char ±
0x00, 0x09, 0x0D, 0x0A, 0x00, 0x00, // Code for char ²
0x00, 0x09, 0x0D, 0x0F, 0x00, 0x00, // Code for char ³
0x00, 0x00, 0x02, 0x01, 0x00, 0x00, // Code for char ´
0xFC, 0x40, 0x40, 0x40, 0x3C, 0x00, // Code for char µ
0x06, 0x0F, 0xFF, 0x01, 0xFF, 0x01, // Code for char ¶
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ·
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ¸
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ¹
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char º
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char »
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ¼
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ½
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ¾
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ¿
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char À
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Á
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Â
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ã
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ä
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Å
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Æ
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ç
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char È
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char É
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ê
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ë
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ì
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Í
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Î
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ï
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ð
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ñ
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ò
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ó
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ô
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Õ
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ö
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ×
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ø
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ù
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ú
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Û
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ü
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Ý
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Þ
0xFE, 0x49, 0x49, 0x56, 0x20, 0x00, // Code for char ß
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char à
0xFE, 0x49, 0x49, 0x56, 0x20, 0x00, // Code for char á
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char â
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ã
0x38, 0x45, 0x44, 0x45, 0x7C, 0x00, // Code for char ä
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char å
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char æ
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ç
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char è
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char é
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ê
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ë
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ì
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char í
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char î
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ï
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ð
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ñ
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ò
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ó
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ô
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char õ
0x30, 0x4A, 0x48, 0x4A, 0x30, 0x00, // Code for char ö
0x08, 0x08, 0x2A, 0x08, 0x08, 0x00, // Code for char ÷
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ø
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ù
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ú
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char û
0x38, 0x42, 0x40, 0x42, 0x78, 0x00, // Code for char ü
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ý
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char þ
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ÿ
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Code for char
};
Display.h
Can someone tell me whats wrong?
Thanks in advance.
Download BugAVRgcc_Char.zip from http://tiny.systems/categorie/lcdProjekt/FragenAntworten.html and extract the new libraries
OLED display is not working with teensy3.2 board, but it is working fine with arduino UNO with the same code as below:
#include <U8glib.h>
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does
not send AC
int frame=0;
const uint8_t frame1[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFE, 0x00, 0x3F, 0xFF, 0xFF, 0x00,
0x3F, 0xFF, 0xFF, 0x80,
0x30, 0x00, 0x01, 0x80, 0x33, 0xFF, 0x81, 0xC0, 0x33, 0xFF, 0x81, 0xE0,
0x33, 0xFF, 0x81, 0xE0,
0x33, 0xFF, 0x81, 0xE0, 0x33, 0xFF, 0x81, 0xE0, 0x33, 0xFF, 0x81, 0xE0,
0x33, 0xFF, 0x81, 0xE0,
0x33, 0xFF, 0x81, 0xE0, 0x33, 0xFF, 0x81, 0xC0, 0x30, 0x00, 0x01, 0x80,
0x3F, 0xFF, 0xFF, 0x80,
0x3F, 0xFF, 0xFF, 0x00, 0x0F, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const uint8_t frame2[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x0F, 0x00,
0x00, 0x09, 0x80, 0x00,
0x08, 0xE0, 0x00, 0x08, 0x38, 0x00, 0x08, 0x1C, 0x0C, 0x08, 0x0F, 0x06,
0x08, 0x1C, 0x03, 0x88,
0x70, 0x00, 0xC8, 0xE0, 0x00, 0x79, 0x80, 0x00, 0x1E, 0x00, 0x00, 0x1E,
0x00, 0x00, 0x79, 0x80,
0x00, 0xC8, 0xE0, 0x03, 0x88, 0x70, 0x06, 0x08, 0x1C, 0x0C, 0x08, 0x0F,
0x00, 0x08, 0x1C, 0x00,
0x08, 0x38, 0x00, 0x08, 0xE0, 0x00, 0x09, 0xC0, 0x00, 0x0F, 0x00, 0x00,
0x0C, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
};
const uint8_t frame3 [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00,
0x00, 0x01, 0x80, 0x00,
0x00, 0x01, 0xC0, 0x00, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x03, 0xC0, 0x00,
0x00, 0x03, 0xC0, 0x00,
0x00, 0x03, 0xC0, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x02, 0x40, 0x00,
0x00, 0x06, 0x40, 0x00,
0x00, 0x06, 0x60, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, 0x06, 0x60, 0x00,
0x00, 0x04, 0x60, 0x00,
0x00, 0x0C, 0x60, 0x00, 0x00, 0x0C, 0x60, 0x00, 0x07, 0xFC, 0x61, 0xFC,
0x07, 0xF8, 0x33, 0xFC,
0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x33, 0x00,
0x00, 0x00, 0x33, 0x00,
0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x3E, 0x00,
0x00, 0x00, 0x1E, 0x00,
0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x1C, 0x00,
0x00, 0x00, 0x1C, 0x00,
0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const uint8_t frame4[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xE0, 0x00, 0x00, 0x01, 0xFF,
0xF8, 0x00, 0x00, 0x07,
0xFF, 0xFE, 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0x00, 0x00, 0x3F, 0xFF, 0xFF,
0x80, 0x00, 0x7F, 0xFF,
0xFF, 0xC0, 0x00, 0xFF, 0xFF, 0xFF, 0xF0, 0x01, 0xFF, 0xFF, 0xFF, 0xF0,
0x01, 0xFF, 0xFF, 0xFE,
0xF8, 0x03, 0xFF, 0xFF, 0xFC, 0x78, 0x03, 0xFF, 0xFF, 0xF8, 0x7C, 0x07,
0xFF, 0xFF, 0xF0, 0xFC,
0x07, 0xFF, 0xFF, 0xE1, 0xFC, 0x0F, 0xFF, 0xFF, 0xC3, 0xFE, 0x0F, 0xFF,
0xFF, 0x87, 0xFE, 0x0F,
0xFF, 0xFF, 0x0F, 0xFE, 0x0F, 0xF3, 0xFE, 0x1F, 0xFE, 0x0F, 0xE1, 0xFC,
0x3F, 0xFE, 0x0F, 0xE0,
0xF8, 0x7F, 0xFE, 0x0F, 0xF0, 0x70, 0xFF, 0xFE, 0x0F, 0xF8, 0x21, 0xFF,
0xFE, 0x0F, 0xFC, 0x03,
0xFF, 0xFE, 0x07, 0xFE, 0x07, 0xFF, 0xFC, 0x07, 0xFF, 0x0F, 0xFF, 0xFC,
0x07, 0xFF, 0x9F, 0xFF,
0xFC, 0x03, 0xFF, 0xFF, 0xFF, 0xF8, 0x01, 0xFF, 0xFF, 0xFF, 0xF8, 0x01,
0xFF, 0xFF, 0xFF, 0xF0,
0x00, 0xFF, 0xFF, 0xFF, 0xE0, 0x00, 0x7F, 0xFF, 0xFF, 0xC0, 0x00, 0x3F,
0xFF, 0xFF, 0x80, 0x00,
0x1F, 0xFF, 0xFF, 0x00, 0x00, 0x0F, 0xFF, 0xFE, 0x00, 0x00, 0x03, 0xFF,
0xF8, 0x00, 0x00, 0x00,
0x7F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
void setup(void) {
}
void loop(void) {
u8g.firstPage();
do{
draw();
}while(u8g.nextPage());
frame++;
if(frame == 13)
frame=0;
delay(1000);
}
void draw(){
if(frame == 0 )
{ u8g.drawBitmapP(0,0,4,20,frame1);
u8g.drawBitmapP(103,0,3.5,28, frame2);
u8g.setFont(u8g_font_helvR24);
u8g.setColorIndex(1);
u8g.drawStr(20,45,"11:45");
u8g.setFont(u8g_font_helvB12);
u8g.drawStr(100,60,"AM");
}
if(frame == 1 )
{ u8g.setFont(u8g_font_profont22);
u8g.setColorIndex(1);
u8g.drawStr(0,20,"Heart Rate");
u8g.setFont(u8g_font_helvR24);
u8g.drawStr(25,60,"75");
u8g.setFont(u8g_font_helvB12);
u8g.drawStr(90,60,"BPM");
}
if(frame == 2 )
{ u8g.setFont(u8g_font_profont22);
u8g.setColorIndex(1);
u8g.drawStr(10,20,"Analysing");
u8g.drawBitmap(10,30,4,32, frame3);
u8g.setFont(u8g_font_helvR24);
u8g.setColorIndex(1);
u8g.drawStr(50,58,"10");
u8g.setFont(u8g_font_profont22);
u8g.drawStr(90,58,"sec");
}
if(frame == 3 )
{ u8g.setFont(u8g_font_profont22);
u8g.setColorIndex(1);
u8g.drawStr(10,20,"Analysing");
u8g.drawBitmap(10,30,4,32, frame3);
u8g.setFont(u8g_font_helvR24);
u8g.setColorIndex(1);
u8g.drawStr(60,58,"9");
u8g.setFont(u8g_font_profont22);
u8g.drawStr(90,58,"sec");
}
if(frame == 4 )
{ u8g.setFont(u8g_font_profont22);
u8g.setColorIndex(1);
u8g.drawStr(10,20,"Analysing");
u8g.drawBitmap(10,30,4,32, frame3);
u8g.setFont(u8g_font_helvR24);
u8g.setColorIndex(1);
u8g.drawStr(60,58,"8");
u8g.setFont(u8g_font_profont22);
u8g.drawStr(90,58,"sec");
}
if(frame == 5 )
{ u8g.setFont(u8g_font_profont22);
u8g.setColorIndex(1);
u8g.drawStr(10,20,"Analysing");
u8g.drawBitmap(10,30,4,32, frame3);
u8g.setFont(u8g_font_helvR24);
u8g.setColorIndex(1);
u8g.drawStr(60,58,"7");
u8g.setFont(u8g_font_profont22);
u8g.drawStr(90,58,"sec");
}
if(frame == 6 )
{ u8g.setFont(u8g_font_profont22);
u8g.setColorIndex(1);
u8g.drawStr(10,20,"Analysing");
u8g.drawBitmap(10,30,4,32, frame3);
u8g.setFont(u8g_font_helvR24);
u8g.setColorIndex(1);
u8g.drawStr(60,58,"6");
u8g.setFont(u8g_font_profont22);
u8g.drawStr(90,58,"sec");
}
if(frame == 7 )
{ u8g.setFont(u8g_font_profont22);
u8g.setColorIndex(1);
u8g.drawStr(10,20,"Analysing");
u8g.drawBitmap(10,30,4,32, frame3);
u8g.setFont(u8g_font_helvR24);
u8g.setColorIndex(1);
u8g.drawStr(60,58,"5");
u8g.setFont(u8g_font_profont22);
u8g.drawStr(90,58,"sec");
}
if(frame == 8 )
{ u8g.setFont(u8g_font_profont22);
u8g.setColorIndex(1);
u8g.drawStr(10,20,"Analysing");
u8g.drawBitmap(10,30,4,32, frame3);
u8g.setFont(u8g_font_helvR24);
u8g.setColorIndex(1);
u8g.drawStr(60,58,"4");
u8g.setFont(u8g_font_profont22);
u8g.drawStr(90,58,"sec");
}
if(frame == 9 )
{ u8g.setFont(u8g_font_profont22);
u8g.setColorIndex(1);
u8g.drawStr(10,20,"Analysing");
u8g.drawBitmap(10,30,4,32, frame3);
u8g.setFont(u8g_font_helvR24);
u8g.setColorIndex(1);
u8g.drawStr(60,58,"3");
u8g.setFont(u8g_font_profont22);
u8g.drawStr(90,58,"sec");
}
if(frame == 10 )
{ u8g.setFont(u8g_font_profont22);
u8g.setColorIndex(1);
u8g.drawStr(10,20,"Analysing");
u8g.drawBitmap(10,30,4,32, frame3);
u8g.setFont(u8g_font_helvR24);
u8g.setColorIndex(1);
u8g.drawStr(60,58,"2");
u8g.setFont(u8g_font_profont22);
u8g.drawStr(90,58,"sec");
}
if(frame == 11 )
{u8g.setFont(u8g_font_profont22);
u8g.setColorIndex(1);
u8g.drawStr(10,20,"Analysing");
u8g.drawBitmap(10,30,4,32, frame3);
u8g.setFont(u8g_font_helvR24);
u8g.setColorIndex(1);
u8g.drawStr(60,58,"1");
u8g.setFont(u8g_font_profont22);
u8g.drawStr(90,58,"sec");
}
if(frame == 12)
{u8g.drawBitmapP(45,0,5.375,43, frame4);
u8g.setFont(u8g_font_profont22);
u8g.setColorIndex(1);
u8g.drawStr(45,58,"Done");
}
}
Their are no compiling errors. The OLED is not even turning on. AND on scanning the address comes out to be 0X3C.I have searched a lot on google but i think theirs and issue in I2C communication.
Please help me out.
#vasu Hi I had the same problem but please also check for any hardware faults before following my answer.
The oled display I bought only had VCC-GND-SCL-SDA. So I don't have a reset PIN here.
But the oled library initially tries to pull the reset PIN high on startup. Since I don't have a reset pin, it sits there and waits for a reset HIGH. So in order to initialise your oled display without reset pin then try this in your Arduino sketch file
//1-->Manually set HIGH to digitally assigned reset pin
pinMode(A4, OUTPUT); //A4 is reset pin assigned programmatically (for example)
digitalWrite(A4, HIGH);
//2-->Try changing your init to this
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);
//As this will be the right one to define from the user manual shown in the link
//https://reprap.org/forum/file.php?267,file=54605
Try the above and let me know how it went.
Cheers