Share My Creation OLED Oscilloscope

OLED low frequency oscilloscope, bandwidth is DC to 1000Hz. Max sampling rate is 16000 samples per second. An oscilloscope with these specifications has limited use, but it is a good exercise in using OLED display. rWire lib is used for I2C. Inline c used to increase speed of I2C to 400KHz.
Arduino Uno or Nano can be used. Oled is 0.96" I2C SSD1306 driver.
The screen is constructed from 64 dots. The ATMEGA ADC reads the input at resolution of 10 bits. The MSB 8 bits are used and the dote position is calculated.
Switch is on for input frequency below 100Hz.
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private master As WireMaster
    Private const addr As Byte = 0x3C
    Private tmr As Timer
    Private in, freq As Pin
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    tmr.Initialize("tmr_Tick", 2000)
    in.Initialize(in.A0, in.MODE_INPUT)
    freq.Initialize(2, freq.MODE_INPUT_PULLUP)
    tmr.Enabled = True
    master.Initialize
    RunNative("speed", Null)    'set I2C to 400KHz
    oled_init
    clr_screen

End Sub

Sub tmr_Tick
    Dim i, x, v, m, smp(64), c(2) As Byte
   
    clr_screen
    For i = 0 To 63
        smp(i)=in.analogRead
        If freq.digitalRead=False Then Delay(1)
    Next  
    c(0)=0x40
    For x=0 To 63
        v=64 - smp(x) / 4
        command(0x21)     'col addr
        command(x*2) 'col start
        command(x*2)  'col End
        command(0x22)    '0x22
        command(v/8) ' Page start
        command(v/8) ' Page End
       
        m = v Mod 8
        If m>2 Then m=Power(2,m-1)+1
        c(1)=m
        master.WriteTo(addr,c)
    Next

End Sub

Sub clr_screen
    Dim x As Byte
    Dim c() As Byte = Array As Byte(0x40,0,0,0,0,0,0,0,0)
   
    For x = 0 To 127
        command(0x21)     'col addr
        command(x) 'col start
        command(x)  'col End
        command(0x22)    '0x22
        command(0) ' Page start
        command(7) ' Page End
        master.WriteTo(addr,c)
    Next

End Sub

Sub command(cmnd As Byte)
    Dim cb(2) As Byte
    cb(0)=0
    cb(1)=cmnd
    master.WriteTo(addr,cb)
End Sub

Sub oled_init
    command(0xAE)   'DISPLAYOFF
    command(0x8D)   '       CHARGEPUMP *
    command(0x14)    ' 0x14-pump on
    command(0x20)    '      MEMORYMODE
    command(0x01)     ' 0x0=horizontal, 0x01=vertical, 0x02=page
    command(0xA1)    '    SEGREMAP * A0/A1=top/bottom
    command(0xC8)    ' COMSCANDEC * C0/C8=left/right
    command(0xDA)     '     SETCOMPINS *
    command(0x12)   '0x22=4rows, 0x12=8rows
    command(0x81)     '    SETCONTRAST
    command(0xFF)     '0x8F
   
    command(0xAF)       '   DISPLAYON
End Sub

#if C
void speed (B4R::Object* o) {
   Wire.setClock(400000);  //400khz
}
#End if
 

Attachments

  • oled_scope2.zip
    1.5 KB · Views: 384
  • oled_scope400.jpg
    oled_scope400.jpg
    19.7 KB · Views: 1,355
  • oled_scope.png
    oled_scope.png
    5.3 KB · Views: 336
Last edited:

Cableguy

Expert
Licensed User
Longtime User
OLED low frequency oscilloscope, bandwidth is DC to 100Hz. Max sampling rate is 1600 samples per second.

Can you explore a bit about the why such limitations and if they are micro-controler limitations, is there a way of working around them?
I ask because one can buy a 2 ch 1Mhz diy oscilloscope kit for about 30$ and I would be curious to know if something similar is achievable HW wise with arduino range/compatible controllers.
 

moty22

Active Member
Licensed User
Can you explore a bit about the why such limitations and if they are micro-controler limitations, is there a way of working around them?
I ask because one can buy a 2 ch 1Mhz diy oscilloscope kit for about 30$ and I would be curious to know if something similar is achievable HW wise with arduino range/compatible controllers.
Hi Cableguy,
1MHz means 2 M sampling per sec, most microcontrollers ADC can do only 20 K s/sec, it's done to achieve low supply current. The ADC is the main limitation, with processing power of an Arduino Uno you can probably make an oscilloscope of 100KHz.
In this project I stretched it to the max of the Arduino, https://www.b4x.com/android/forum/threads/arduino-oscilloscope.119443/
 

Cableguy

Expert
Licensed User
Longtime User
With an external ADC with its own clock doing the data acquisition and the Arduino (more likely EsP32) just to process and display... could that go to the 1Mhz?
All this is just out of curiosity... no real application.
 

moty22

Active Member
Licensed User
With an external ADC with its own clock doing the data acquisition and the Arduino (more likely EsP32) just to process and display... could that go to the 1Mhz?
Yes, the ESP32 is fast enough. The speed is needed to read the ADC and store enough data to build one screen, then you can take your time displaying it to the slow human eye. The more detailed picture you need the more data you need to store.
 
Top