moved examples to a folder
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
#!/bin/env python3
|
||||
import gex
|
||||
|
||||
with gex.Client(gex.TrxRawUSB()) as client:
|
||||
# Neopixel strip
|
||||
strip = gex.Neopixel(client, 'npx')
|
||||
# Load RGB to the strip
|
||||
strip.load([0xFF0000, 0x00FF00, 0x0000FF, 0xFF00FF])
|
||||
#
|
||||
# # I2C bus
|
||||
# i2c = gex.I2C(client, 'i2c')
|
||||
# # Read device register
|
||||
# print(i2c.read_reg(address=0x76, reg=0xD0))
|
||||
# # Write value to a register
|
||||
# i2c.write_reg(address=0x76, reg=0xF4, value=0xFA)
|
||||
#
|
||||
# # SPI
|
||||
# spi = gex.SPI(client, 'spi')
|
||||
# # Query slave 0
|
||||
# print(spi.query(0, [0xAA, 0xBB, 0xCC, 0xDD], rlen=2, rskip=4))
|
||||
# # Write slaves 0 and 2
|
||||
# spi.multicast(0b101, [0xDE, 0xAD, 0xBE, 0xEF])
|
||||
#
|
||||
# # USART
|
||||
# usart = gex.USART(client, 'serial')
|
||||
# # Handle received data
|
||||
# usart.listen(lambda x: print(x, end='', flush=True))
|
||||
# # Write a string
|
||||
# usart.write("AHOJ\r\n")
|
||||
#
|
||||
# # Digital output (8 pins)
|
||||
# display = gex.DOut(client, 'display')
|
||||
# display.write(0b10110011)
|
||||
# display.toggle(0b00010010)
|
||||
|
||||
@@ -8,6 +8,8 @@ import datetime
|
||||
|
||||
from scipy.io import wavfile
|
||||
|
||||
# this script captures lightnings and stores them to npy files
|
||||
|
||||
# ADC channel 1 -> 100n -> o -> long wire (antenna)
|
||||
# |
|
||||
# '-> 10k -> GND
|
||||
@@ -2,6 +2,8 @@
|
||||
import gex
|
||||
import time
|
||||
|
||||
# simple demo with the dot matrix phat
|
||||
|
||||
ADDR = 0x61
|
||||
MODE = 0b00011000
|
||||
OPTS = 0b00001110 # 1110 = 35mA, 0000 = 40mA
|
||||
@@ -4,6 +4,9 @@ import random
|
||||
import gex
|
||||
import time
|
||||
|
||||
# This is an adaptation of the micro dot phat library
|
||||
# - the only change needed was replacing the smbus class with the GEX unit driver
|
||||
|
||||
ADDR = 0x61
|
||||
MODE = 0b00011000
|
||||
OPTS = 0b00001110 # 1110 = 35mA, 0000 = 40mA
|
||||
@@ -19,9 +22,6 @@ CMD_MATRIX_2 = 0x0E
|
||||
MATRIX_1 = 0
|
||||
MATRIX_2 = 1
|
||||
|
||||
# This is an adaptation of the phat library
|
||||
# - the only change needed was replacing the smbus class with the GEX unit driver
|
||||
|
||||
class NanoMatrix:
|
||||
'''
|
||||
_BUF_MATRIX_1 = [ # Green
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/bin/env python3
|
||||
import gex
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
# frequency response measurement
|
||||
|
||||
with gex.Client(gex.TrxRawUSB()) as client:
|
||||
dac = gex.DAC(client, 'dac')
|
||||
adc = gex.ADC(client, 'adc')
|
||||
|
||||
dac.waveform(1, 'SINE')
|
||||
adc.set_sample_rate(50000)
|
||||
|
||||
table = []
|
||||
|
||||
for i in range(100, 10000, 100):
|
||||
dac.set_frequency(1, i)
|
||||
data = adc.capture(10000)
|
||||
# convert to floats
|
||||
samples = data.astype(float)
|
||||
amplitude = np.max(samples) - np.min(samples)
|
||||
print("%d Hz ... rms %d" % (i, amplitude))
|
||||
table.append(i)
|
||||
table.append(amplitude)
|
||||
|
||||
dac.dc(1, 0)
|
||||
|
||||
t = np.reshape(np.array(table), [int(len(table)/2),2])
|
||||
hz = t[:,0]
|
||||
am = t[:,1]
|
||||
|
||||
plt.plot(hz, am, 'r-', lw=1)
|
||||
plt.grid()
|
||||
plt.show()
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/env python3
|
||||
import gex
|
||||
|
||||
# experiment with the dot matrix driver
|
||||
|
||||
with gex.Client(gex.TrxRawUSB()) as client:
|
||||
bus = gex.I2C(client, 'i2c')
|
||||
addr = 0x61
|
||||
bus.write_reg(addr, 0x00, 0b00011000) # dual matrix
|
||||
bus.write_reg(addr, 0x0D, 0b00001110) # 34 mA
|
||||
bus.write_reg(addr, 0x19, 64) # set brightness
|
||||
# matrix 1
|
||||
bus.write_reg(addr, 0x01, [
|
||||
0xAA, 0x55, 0xAA, 0x55,
|
||||
0xAA, 0x55, 0xAA, 0x55
|
||||
])
|
||||
# matrix 2
|
||||
bus.write_reg(addr, 0x0E, [
|
||||
0xFF, 0x00, 0xFF, 0x00,
|
||||
0xFF, 0x00, 0xFF, 0x00
|
||||
])
|
||||
# update display
|
||||
bus.write_reg(addr, 0x0C, 0x01)
|
||||
@@ -2,6 +2,8 @@ import time
|
||||
|
||||
import gex
|
||||
|
||||
# NDIR CO2 sensor showing the concentration on a SIPO-based LED display
|
||||
|
||||
with gex.Client(gex.TrxRawUSB()) as client:
|
||||
ser = gex.USART(client, 'ser')
|
||||
leds = gex.SIPO(client, 'leds')
|
||||
@@ -2,6 +2,8 @@ import time
|
||||
|
||||
import gex
|
||||
|
||||
# basic NDIR CO2 sensor readout
|
||||
|
||||
with gex.Client(gex.TrxRawUSB()) as client:
|
||||
ser = gex.USART(client, 'ser')
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
import gex
|
||||
import time
|
||||
|
||||
# play a little neopixel animation as a demo
|
||||
|
||||
with gex.Client(gex.TrxRawUSB()) as client:
|
||||
# Neopixel strip
|
||||
strip = gex.Neopixel(client, 'npx')
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/env python3
|
||||
import gex
|
||||
|
||||
# the most basic neopixel demo
|
||||
|
||||
with gex.Client(gex.TrxRawUSB()) as client:
|
||||
# Neopixel strip
|
||||
strip = gex.Neopixel(client, 'npx')
|
||||
# Load RGB to the strip
|
||||
strip.load([0xFF0000, 0x00FF00, 0x0000FF, 0xFF00FF])
|
||||
|
||||
@@ -5,7 +5,6 @@ import sx_fsk as sx
|
||||
|
||||
|
||||
# this is a demo with two NRF24L01+ modules connected to SPI and some GPIO.
|
||||
# using the ESB function.
|
||||
|
||||
class Nrf:
|
||||
def __init__(self, ce: gex.DOut, irq: gex.DIn, spi: gex.SPI, num):
|
||||
@@ -2,6 +2,8 @@
|
||||
import gex
|
||||
import time
|
||||
|
||||
# generating a pulse on gpio, test of the unit
|
||||
|
||||
with gex.Client(gex.TrxRawUSB()) as client:
|
||||
out = gex.DOut(client, 'out')
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import time
|
||||
import gex
|
||||
|
||||
# GEX pomodoro timer
|
||||
|
||||
# button btn
|
||||
# neopixel neo
|
||||
|
||||
# this is an example of using GEX as a user interface.
|
||||
# for practical use it would be better to make this into a standalone device with a custom firmware.
|
||||
|
||||
WK_TIME = 25
|
||||
BK_TIME = 5
|
||||
LIGHT_CNT = 30
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/bin/env python3
|
||||
import time
|
||||
|
||||
import gex
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
from scipy.io import wavfile
|
||||
|
||||
# catching a transient
|
||||
|
||||
with gex.Client(gex.TrxRawUSB()) as client:
|
||||
adc = gex.ADC(client, 'adc')
|
||||
|
||||
rate=50000
|
||||
fs = adc.set_sample_rate(rate)
|
||||
|
||||
d = None
|
||||
|
||||
def x(report):
|
||||
global d
|
||||
print("capt")
|
||||
d = report
|
||||
|
||||
adc.on_trigger(x)
|
||||
adc.setup_trigger(0, 50, 600, edge='rising', pretrigger=100)
|
||||
adc.arm()
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
if d is not None:
|
||||
plt.plot(d.data, 'r-', lw=1)
|
||||
plt.grid()
|
||||
plt.show()
|
||||
else:
|
||||
print("Nothing rx")
|
||||
|
||||
@@ -2,6 +2,8 @@ import time
|
||||
|
||||
import gex
|
||||
|
||||
# beeping music with PWM (square wave)
|
||||
|
||||
C3 = 130.81; Cx3 = 138.59; D3 = 146.83; Dx3 = 155.56; E3 = 164.81; F3 = 174.61
|
||||
Fx3 = 185.00; G3 = 196.00; Gx3 = 207.65; A3 = 220.00; Ax3 = 233.08; B3 = 246.94
|
||||
C4 = 261.63; Cx4 = 277.18; D4 = 293.66; Dx4 = 311.13; E4 = 329.63; F4 = 349.23
|
||||
@@ -2,6 +2,8 @@ import time
|
||||
|
||||
import gex
|
||||
|
||||
# pwm frequency sweep
|
||||
|
||||
with gex.Client(gex.TrxRawUSB()) as client:
|
||||
pwm = gex.PWMDim(client, 'dim')
|
||||
|
||||
@@ -2,6 +2,8 @@ import time
|
||||
|
||||
import gex
|
||||
|
||||
# sipo example
|
||||
|
||||
with gex.Client(gex.TrxRawUSB()) as client:
|
||||
sipo = gex.SIPO(client, 'sipo')
|
||||
d4 = gex.DOut(client, 'd4')
|
||||
@@ -2,6 +2,8 @@ import time
|
||||
|
||||
import gex
|
||||
|
||||
# toush sensing test
|
||||
|
||||
with gex.Client(gex.TrxRawUSB()) as client:
|
||||
tsc = gex.TOUCH(client, 'tsc')
|
||||
|
||||
@@ -3,6 +3,8 @@ import time
|
||||
|
||||
import gex
|
||||
|
||||
# test with the radio gw
|
||||
|
||||
with gex.DongleAdapter(gex.TrxRawUSB(remote=True), 0x10) as transport:
|
||||
# with gex.TrxRawUSB() as transport:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user