Goldln
How to connect the screen via I2C. It would be very useful for PLC assemblies if you can show an example of this connection.
Reply 3 0
yonush
It is possible but you have you to add additional code in various folders and files. I had the SSD3306 OLED (128x32 & 128x64) mostly working by creating a FB and some Arduino code. I edited:
  • editor\arduino\examples\Baremetal (arduino_libs.h)
  • editor\arduino\src\lib (arduino_lib_FB.h, arduino.txt)
  • matiec\lib (arduino.txt)
  • editor\plcopen (Arduino_Function_Blocks.xml)
I also did this to add in the DHT11 too to have the following in the editor.
 
[203128%2F8138820%2Fmceclip0]
 
Needless to say it is not very efficient because the OLED & DHT are very slow. I was going to add some threading but never got further than that.  The DHT works fine but the OLED code certainly needs more work.
Reply 3 0
Goldln
I would just like to add OLEDs to show the switching of inputs and outputs. That would be very nice.
Reply 0 0
Goldln
Can you send your development, just to see what's what, to understand how it works.
Reply 0 0
Goldln
And how to connect
Reply 0 0
yonush
I have created an archive of the  files that were either modded or added to give the DHT11 and OLED capabilities.
You will need to add the 'Adafruit_SSD1306' and 'Adafruit_GFX' libraries to the Arduino distribution.
You should be able to do that through the Arduino IDE or using the arduino-cli.exe tool (a copy is in the OpenPLC folder editor\arduino\bin).
 
I have been using the Raspberry Pi Pico for my dev work with a custom PCB (pic below) to work as a PLC for teachingzipopenplc OLED mods.zip. The code still needs some work but I have not had the time to focus on it.
I am just using the onboard I2C for the Pico but you can use any support device that works with OpenPLC and has I2C.  You need to edit the arduino_libs.h file to change the I2C pin allocation.
 
 
The DHT is a one wire so any GPIO pin would work. The code does work but can be somewhat blocking owing to the slow nature of the DHT. I think it does work ok if you add another task the the PLC program with a slower poll.
 
picoPLC_cr.png
Reply 2 0
Goldln
I can not understand what to change in the code to make OLED work on ESP32.
Reply 0 0
yonush
I have only worked on support for the SSD1306 OLED chips so if you need to use an different chipset you would need to rewrite the code in the editor\arduino\examples\Baremetal\arduino_libs.h file.
The code you need to work on is wrapped in the  #ifdef USE_OLED_BLOCK . . .  #endif
 
Do note, the code is still buggy and I have had unexpected behaviour using it (using a Pico). Mainly owing to its slow update rate that interferes with the 20ms PLC loop. Feel free to change this code just so long as you dont change the line1, line2, line3 variables otherwise you will have to begin editing other files too that use these (editor\arduino\src\lib\arduino_lib_FB.h, editor\arduino\src\lib\arduino_lib_FB.h\arduino.txt and some other files in the matiec folder for the ST->C compiler)
 
I think for the ESP32 the main changes would firstly be the I2C pins used. Look at the line with
"TwoWire CustomI2C0(0, 1);" for the SDA, SCL assignment (https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/).
 
This is the source article i used to write the OLED code - https://learn.adafruit.com/monochrome-oled-breakouts?view=all
 
Sorry I have not had much time to work on this as I did it mainly as a proof of concept exercise.
Reply 0 0
Goldln
I want to connect the SSD1306 to ESP32.To use in my project
Reply 0 0
yonush
If you use the links I suggested above, then you should be able to change the code to work with the ESP32. I have not tested it on an ESP32 but you can compile code for the ESP32 in Arduino therefore making the necessary changes should work for you.
Reply 0 0
Goldln
Thanks for the tip. I'll give it a try.
Reply 0 0
Kristoffer
Hi has somebody worked any more on this topic? Is there a newer beter code? I would like to run the ssd1306 with an arduino to show some sensor data..
 
Tanks in advance
K
Reply 0 0
yonush
 
I have not looked at the code in some time and I am hoping to get back to it later. The code I wrote, above, work for the older version of OpenPLC albeit somewhat buggy. 
 
When I get a chance I will revisit the code and migrate it over to the newer OpenPLC codebase. It does require some rethinking because the SSD1306 is not exactly a fast device, especially when you have a 20ms loop.
 
John
Reply 0 0
Kristoffer
Hi John
Ok i will hava a look at it and se. But i am not skilled enough i think 🙁 . what is the difference that has to be managed compared to the old OpenPLC?
 
Tanks in advance
Kristoffer
Reply 0 0
MattDemon
Hi,
 
Thanks yonush, your contribution helped me a lot !
 
Solution in attached file, for NodeMCU (ESP8266) but not translate in English for the moment.
Matt
Reply 2 0
Reply