I2C SSD1306 scrolling without scroll instrucitons

mikemontauk

Active member
Hi! Full code attached; video here https://drive.google.com/file/d/1ByJGH3-74UsAg6_n22N2JxHRnuG7SkjR/view?usp=sharing

This project receives midi notes (songs) and illuminates LEDs in time with the notes. When a user presses a button the next 5 notes received are mapped to 5 LEDs; then, when any of those 5 notes is/are received, the corresponding led(s) is/are illuminated. If a note that is not assigned to an led is received an error message occurs. This is a primitive "Midi Decoder" as some call it.

The display is scrolling left to right but I have no scroll instruction in my code.

I'm using the Teensy LC.

For reference I am using: 'MakerFocus 2pcs I2C OLED Display Module 0.91 Inch I2C SSD1306 OLED Display Module White I2C OLED Screen Driver DC 3.3V~5V for Ar duino' (it was 2 for $8.68 on amazon)

The 4 display pins are wired to Teensy LC's 3.3v, GND, SCL0 SDA0 and the display is otherwise working and displaying the correct content. It seems like every time a display.X executes it scrolls the origin right one pixel but my origin is always 0,0.
(the mosfet circuit on the board is not being used)

If anyone knows why this is occurring or how to fix it I would really appreciate some help, thanks!

Tomorrow I am going to post about speeding up the code because it can't keep up with fast MIDI songs. (The output starts lagging behind the song.)
 

Attachments

  • midi_decoder_20211104.ino
    13.5 KB · Views: 36
I had the exact same problem with the same screen and a Teensy LC. I added 2.2k pull-up resistors to the SDA and SCL pins and all is well. Hope that helps.
 
Three observations after a brief perusal of the code.
In the OnNoteOn function you have:
Code:
  if (mapStatus>0) {                                                //Executes if button is pressed (mapStatus = 1)

    if (assignedNoteArrayIndex < 5) {                                 //iterates 5 times to map midi notes (pitches) to the 5 outputs
      Serial.print("assignedNoteArrayIndex: ");
      Serial.println(assignedNoteArrayIndex);
      assignedNoteArray[assignedNoteArrayIndex] = note;
      Serial.print("assignedNoteArray[assignedNoteArrayIndex}: ");
      Serial.println(assignedNoteArray[assignedNoteArrayIndex]);
      assignedNoteArrayIndex = assignedNoteArrayIndex+1;
      Serial.print("assignedNoteArrayIndex+1: ");
      Serial.println(assignedNoteArrayIndex);
      if (assignedNoteArrayIndex > 4) {
Since assignedNoteArrayIndex is an integer, if it is less than 5, it can not be greater than 4 and so the code in the if(... > 4) will never be executed.

There is a huge amount Serial output on each received MIDI note. This is probably slowing things down. Try minimizing this output.

I think the big problem is probably going to be that when you match one of the MIDI notes you clear the display and refresh all its info every time. However, the only things that actually change on the display are the actual note number, channel, and velocity. You can write all the text, such as "Note On:" on the display once and then when a note is matched, just move the display cursor to the correct position on each line and write only the relevant number.


Pete
 
Thank you very much for your feedback. I trust this is a viable solution. I ended up switching to an SPI display and the speed is greatly preferable. Thanks again and take care!
 
Thank you very much a27x64sy for your feedback. I trust the 2.2k pullup is a viable solution. I ended up switching to an SPI display and the speed is greatly preferable. Thanks again and take care!
 
Hi Pete, I will look into the loop again. I beleive my intention was: the assignedNoteArrayIndex, when it is 4, the loop executes and assignedNoteArrayIndex+1 makes it 5; then the loop does not execute and the next (>4) loop executes.

I greatly appreaciate your input and I belive the most valuable takeaway for me is your suggestion to update only the note number, channel, and velocity. I will have to learn more about how to update specific variables using the 'display cursor'. It sounds promising. I actually moved to an SPI display and the scrolling is gone and there is no more latency, BUT...I still want to optimize as much as possible, therefore your suggestion still stands as great advice.

Thanks again and take care.
 
Back
Top