can somebody help me with me this program? - Page 1
Forum section: electronics / beginners

author: rizlesz2000
author_rank: Contributor
timestamp: October 20, 2023, 05:21:14 am
content: can somebody help me with this program to convert from normal sh1106 oled library to u8g2lib SH1106 HW noname i2c library since esp32c3 xiao isn't an avr microcontroller? i have been painstaking on this program for a month and nobody wants to help me. I had almost finished the hardware and don't want to destroy it.the program is posted below (it's a text file so just open it and copy it to arduino)https://github.com/olikraus/u8g2/wiki

author: darkspr1te
author_rank: Frequent Contributor
timestamp: October 20, 2023, 06:05:48 am
content: Hi,I find myself in this situation quite often, the need to use a code base but having to port parts for your needs, often without know how too :-)the two libs you are facing , the old and the new are close in the way they are applied.in the old code you have the lib in the include sectionCode:#include <Adafruit_GFX.h>#include <Adafruit_SH1106.h>in your new code you will need to swap these out for the u8g2 includes (load up one of the demos to see what you need to copy and paste )then there is the calls to the lcd lib you will need to swap out again,Code:Adafruit_SH1106 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);again just look at a demo in the u8g2 folder for the gfx call it uses.finally you will have to go through all the code replacing the old display commands for the new commands ,exampleCode:display.clearDisplay();display.print("-------");display.print(" SLEEP ");display.print("-------");display.display();delay(2000);new codeCode:u8x8.clear();u8x8.drawString(0,0,"--------");u8x8.drawString(0,0,"SLEEP");u8x8.drawString(0,0,"---------");often you might find the old lib does something one way and the new lib another, a example is in the old lib you set the cursor position, in the new lib you send cursor position with each display call, so you may find yourself removing code that just does that or having to add code to convert between formats or iterationsI would try and get proficient in writing some mini programs using the new library , just little demos to test the hardware out and interact with it first before you stress yourself jumping to head long into "porting code " that you have no background or experience in, it can get quite dis-heartening when code just wont compile or act the way it's ment to so sometimesThen I will start a new project on the device in question and bit by bit add code from the port project into my new code base and test my compile each time. I usually target the routines that dont rely on calling something else or use a lib i am well versed in. a example would be say you porting a program that uses unknown lcd lib but also a well known i2c lib that you know, so i would start on the i2c side of the code and start bringing that in to my new program. when it comes to function that uses the lcd i would leave place holders eg:Code:uint8_t numberA,NumberB;uint8_t result_i_need = function_do_math(numberA,numberB);//display results old way//lcd.display(0,0,result_i_need);//new waySerial.print(result_i_need);//do other codecode();In the above example i am just using the serial port to display my info instead, this wont work with graphics but for debuggin and displaying test/numbers its a quick substitute while you trying to get other code to work.I hope this helps youdarkspr1te