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.
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
Last edited: