How to display Variables from a script on to an OLED using simulink
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
hello
I am having an issue displaying variables on my OLED Display (ssD 13150) im a bit new to matlab and think i need to use simulink but am not sure and vcant find to much info on using oled displys in matlab , does anyone have any resources or tips they can give me
Accepted Answer
Walter Roberson
on 21 Oct 2023
Use simulink arduino I2C blocks; https://www.mathworks.com/matlabcentral/answers/318267-how-to-communicate-with-the-arduino-i2c-in-simulink
https://www.mathworks.com/matlabcentral/answers/512483-how-to-control-ssd1306-128x32-oled-display-in-matlab#answer_1149845 gives an example of the I2C that would be needed to turn on a SSD1306
https://www.mathworks.com/help/supportpkg/arduino/ref/adxl343-read-acceleration-tap-count-oled-io-device-builder.html shows an example of creating custom I/O blocks that use I2C to talk to an OLED that is compatible with SH1106 . I am not sure if you will need to go that far
14 Comments
Jack
on 21 Oct 2023
okay so ive read over the exmaples and from my undertanding i need to use an I2C controller write block toi use for writing text onto the oled display ? Although im bit confused with finding slave address . Also if i just wanted to display a variable on the oled that has a constant value do i need to use simulink or is there a write function I can use , like a write function ?
Walter Roberson
on 21 Oct 2023
You do not need to use Simulink to write to an OLED attached to an arduino. At the MATLAB level you would create the arduino object, probably asking for the appropriate Adafruit library to be loaded, and you would use the arduino I2c functions https://www.mathworks.com/help/supportpkg/arduinoio/i2c-devices.html
You can use https://www.mathworks.com/help/supportpkg/arduinoio/ref/scani2cbus.html to discover i2c slave addresses.
Jack
on 21 Oct 2023
okay so i looked at the resoucres your provided and think i made some progress , i tried making a test scrpit :
clear
a = arduino('COM8','Nano3','Libraries','I2C')
addrs = scanI2CBus(a)
dev = device(a,'I2CAddress','0x3c')
data= [ 1 2 3 4 5]
write(dev,data)
But my oled does not display anything and appears to be off , i think im misisng some sort of intilizing function , I found a library that I think i need to use : https://github.com/adafruit/Adafruit_SSD1306
could you point me in the right direction ?
Walter Roberson
on 21 Oct 2023
Edited: Walter Roberson
on 21 Oct 2023
Jack
on 21 Oct 2023
yeah thats what i was basing my code off but oled doesnt turn on
Walter Roberson
on 21 Oct 2023
Edited: Walter Roberson
on 21 Oct 2023
I am having difficulty finding an OLED with part #13150 . Are you possibly using a 3150 ? https://www.adafruit.com/product/3150
I suspect not as the address for that has to be 0x70 to 0x77
Jack
on 21 Oct 2023
ssd: 1315, 0.96''
Jack
on 21 Oct 2023
I think we are thinking about two diffrent devices
Walter Roberson
on 22 Oct 2023
The slave address for that device is either '0x3C' or '0x3D'; you would typically use 0x3c for the "left" display if you are using two of them.
You can writeRegister() a stream of bytes. The bytes must be in pairs.
If the first (0x80) bit of the first of the pair is 0 then the next bit should be 1 and rest of the bits in the byte should be 0, and the second byte must be a data byte, and that must be the end of the sequence -- so 0x40 then the last byte. (Except as I read the manual, 0x00 then the last byte should work as well, but there is a potential contradiction in the documentation and 0x40 would be safer.)
If the first (0x80) bit of the first of the pair is 1 then the next (0x40) bit determines whether the following byte is a command byte (bit is 0) or a data byte (bit is 1), and the remaining 6 bits of the first byte must be 0. There must be additional bytes in the sequence.
There is an implication that every sequence of bytes must end in 0x00 followed by a data byte -- and therefore there are no "pure command" sequences.
You can send a pure sequence of data bytes by interleaving 0xc0 <data> until a final 0x40 <last data> . Each of those data bytes would be stored in the next location in memory.
It looks like "display on and clear" is 0xA5 and "display on without clearing" is 0xA4 ... except 0xAF also appears to be to set the display on.
Jack
on 22 Oct 2023
okay sweet thanks ill give that a try right now and let you know how it goes thanks boss man
Walter Roberson
on 22 Oct 2023
Note that what gets sent as data to the display is not characters -- not unless the adafruit library provides an interface to help with that.
What gets sent as data is a byte whose bits become vertical pixels. It is up to your code to rasterize the output you want to create something useful to the user. (I would guess that the library contains routines that assist with that.)
For example you might want to construct an array of rendered monospace characters in an 8 pixel by 8 pixel typeface as a bit-map, and then convert the binary columns to 8-bit bytes.
Jack
on 24 Oct 2023
hey so ive been trying to fiddle with the oled and the doc you sent but i cannot for the life of me print to the oled , would you be able to provide me with a code for printing hello world to the oled so i can try top reverse engineer it
Walter Roberson
on 24 Oct 2023
Jack
on 25 Oct 2023
works thanks bro
More Answers (0)
Categories
Find more on Arduino Hardware in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)