Itsybitsy displays voltage reading on OLED and runs the program generator.
I was able to see the voltage reading on OLED but do not see the output of the function generator when powered using BAT pin.
Connected the itsy bitsy to USB cable, and I was able to read voltage, and see the output of the function generator.
Code: Select all
import time
import board
import displayio
import terminalio
import adafruit_displayio_ssd1306
import cedargrove_ad9833 # Update CS pin, and MCLK
import adafruit_ads1x15.ads1115 as ADS
from adafruit_display_text import label
from adafruit_ads1x15.analog_in import AnalogIn
# from analogio import AnalogIn
from digitalio import DigitalInOut, Direction, Pull
# establish class instance with chip_select pin D6
wave_gen = cedargrove_ad9833.AD9833(select="D7")
# OLED Connection
displayio.release_displays()
# Using I2C connection
i2c = board.I2C()
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C) # OLED Address
ads = ADS.ADS1115(i2c, address=0x48) # ADC module ADDRESS
# OLED Dimension
WIDTH = 128
HEIGHT = 32
BORDER = 1
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT)
view = displayio.Group()
display.show(view)
text_area = label.Label(terminalio.FONT, text="", color=0xFFFFFF, x=1, y=10 // 2 - 1)
text1_area = label.Label(terminalio.FONT, text="", color=0xFFFFFF, x=1, y=30 // 2 - 1)
view.append(text_area)
view.append(text1_area)
# Create single-ended input on channel 0
chan = AnalogIn(ads, ADS.P0)
ads.gain = 2 / 3
# Chirp Signal Output
# establish initial parameters
begin_freq = 200000 # fixed or sweep starting frequency (Hz)
end_freq = 250000 # sweep ending freque
inc_freq = 100 # sweep freqency step size (Hz)
wave_type = "sine" # sine, triangle, or square waveform
wave_gen.reset() # reset and stop the wave generator; reset all registers
wave_gen.wave_type = wave_type # load the waveform type value
time.sleep(0.1)
# Initialize Press button to start chirping.
switch = DigitalInOut(board.D2)
switch.direction = Direction.INPUT
switch.pull = Pull.UP
while True:
# Run Chirp when switch is pressed
if not switch.value:
analog_in1 = 0
FreqResonant = 0
total = 0
# analogfinal = 0 # Averaging analog data
# set begin freq value to reduce start-up noise
wave_gen.update_freq(begin_freq)
wave_gen.start() # start the wave generator
for i in range(begin_freq, end_freq, inc_freq):
wave_gen.update_freq(i) # load the next frequency value
analog_in2 = chan.voltage
if analog_in2 > analog_in1:
analog_in1 = analog_in2
FreqResonant = i
wave_gen.stop() # stop the wave generator
resistor = 0.1369 * analog_in1
text_area.text = "R = " + str(resistor)
text1_area.text = "V =" + str(analog_in1)
time.sleep(0.05)
else:
text_area.text = "Connected"
text1_area.text = " "