From 827c714dafe298db8097aad153b7de757cfda4e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Tue, 22 May 2018 10:14:28 +0200 Subject: [PATCH] moved examples to a folder --- demo_neopixel.py | 35 ------------------ .../demo_adc_lightnings.py | 2 + .../demo_dot_matrix_phat.py | 2 + .../demo_dot_matrix_phat2.py | 6 +-- examples/demo_freq_response.py | 35 ++++++++++++++++++ examples/demo_i2c_dotmatrix.py | 23 ++++++++++++ demo_lora.py => examples/demo_lora.py | 0 .../demo_ndir_leds.py | 2 + .../demo_ndir_usart.py | 2 + demo_neo2.py => examples/demo_neo2.py | 2 + demo_neo3.py => examples/demo_neo3.py | 0 examples/demo_neopixel.py | 11 ++++++ demo_nrf24.py => examples/demo_nrf24.py | 1 - demo_pulse.py => examples/demo_pulse.py | 2 + demo_pymodoro.py => examples/demo_pymodoro.py | 8 ++++ examples/demo_transient.py | 37 +++++++++++++++++++ loratest.txt => examples/loratest.txt | 0 main.py => examples/main.py | 0 mat_sampling.m => examples/mat_sampling.m | 0 nrf_config.ini => examples/nrf_config.ini | 0 show_nparray.py => examples/show_nparray.py | 0 sx_fsk.py => examples/sx_fsk.py | 0 test_adc.py => examples/test_adc.py | 0 test_adc2.py => examples/test_adc2.py | 0 test_dac.py => examples/test_dac.py | 0 test_freq_cap.py => examples/test_freq_cap.py | 0 test_ini.py => examples/test_ini.py | 0 test_onewire.py => examples/test_onewire.py | 0 test_ping.py => examples/test_ping.py | 0 .../test_pwmdim_music.py | 2 + .../test_pwmdim_sweep.py | 2 + .../test_sipo_omicron.py | 2 + test_touch.py => examples/test_touch.py | 2 + test_dongle.py | 2 + 34 files changed, 139 insertions(+), 39 deletions(-) delete mode 100644 demo_neopixel.py rename demo_adc_lightnings.py => examples/demo_adc_lightnings.py (94%) rename demo_dot_matrix_phat.py => examples/demo_dot_matrix_phat.py (90%) rename demo_dot_matrix_phat2.py => examples/demo_dot_matrix_phat2.py (98%) create mode 100644 examples/demo_freq_response.py create mode 100644 examples/demo_i2c_dotmatrix.py rename demo_lora.py => examples/demo_lora.py (100%) rename demo_ndir_leds.py => examples/demo_ndir_leds.py (92%) rename demo_ndir_usart.py => examples/demo_ndir_usart.py (91%) rename demo_neo2.py => examples/demo_neo2.py (89%) rename demo_neo3.py => examples/demo_neo3.py (100%) create mode 100644 examples/demo_neopixel.py rename demo_nrf24.py => examples/demo_nrf24.py (99%) rename demo_pulse.py => examples/demo_pulse.py (66%) rename demo_pymodoro.py => examples/demo_pymodoro.py (93%) create mode 100644 examples/demo_transient.py rename loratest.txt => examples/loratest.txt (100%) rename main.py => examples/main.py (100%) rename mat_sampling.m => examples/mat_sampling.m (100%) rename nrf_config.ini => examples/nrf_config.ini (100%) rename show_nparray.py => examples/show_nparray.py (100%) rename sx_fsk.py => examples/sx_fsk.py (100%) rename test_adc.py => examples/test_adc.py (100%) rename test_adc2.py => examples/test_adc2.py (100%) rename test_dac.py => examples/test_dac.py (100%) rename test_freq_cap.py => examples/test_freq_cap.py (100%) rename test_ini.py => examples/test_ini.py (100%) rename test_onewire.py => examples/test_onewire.py (100%) rename test_ping.py => examples/test_ping.py (100%) rename test_pwmdim_music.py => examples/test_pwmdim_music.py (97%) rename test_pwmdim_sweep.py => examples/test_pwmdim_sweep.py (91%) rename test_sipo_omicron.py => examples/test_sipo_omicron.py (95%) rename test_touch.py => examples/test_touch.py (95%) diff --git a/demo_neopixel.py b/demo_neopixel.py deleted file mode 100644 index a3b8a18..0000000 --- a/demo_neopixel.py +++ /dev/null @@ -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) - diff --git a/demo_adc_lightnings.py b/examples/demo_adc_lightnings.py similarity index 94% rename from demo_adc_lightnings.py rename to examples/demo_adc_lightnings.py index 65d2f97..88b11ef 100644 --- a/demo_adc_lightnings.py +++ b/examples/demo_adc_lightnings.py @@ -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 diff --git a/demo_dot_matrix_phat.py b/examples/demo_dot_matrix_phat.py similarity index 90% rename from demo_dot_matrix_phat.py rename to examples/demo_dot_matrix_phat.py index 10eea18..1834038 100644 --- a/demo_dot_matrix_phat.py +++ b/examples/demo_dot_matrix_phat.py @@ -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 diff --git a/demo_dot_matrix_phat2.py b/examples/demo_dot_matrix_phat2.py similarity index 98% rename from demo_dot_matrix_phat2.py rename to examples/demo_dot_matrix_phat2.py index 82b4727..2cbefd0 100644 --- a/demo_dot_matrix_phat2.py +++ b/examples/demo_dot_matrix_phat2.py @@ -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 diff --git a/examples/demo_freq_response.py b/examples/demo_freq_response.py new file mode 100644 index 0000000..d6d3726 --- /dev/null +++ b/examples/demo_freq_response.py @@ -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() diff --git a/examples/demo_i2c_dotmatrix.py b/examples/demo_i2c_dotmatrix.py new file mode 100644 index 0000000..52fe73b --- /dev/null +++ b/examples/demo_i2c_dotmatrix.py @@ -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) diff --git a/demo_lora.py b/examples/demo_lora.py similarity index 100% rename from demo_lora.py rename to examples/demo_lora.py diff --git a/demo_ndir_leds.py b/examples/demo_ndir_leds.py similarity index 92% rename from demo_ndir_leds.py rename to examples/demo_ndir_leds.py index a22af1c..069db3f 100644 --- a/demo_ndir_leds.py +++ b/examples/demo_ndir_leds.py @@ -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') diff --git a/demo_ndir_usart.py b/examples/demo_ndir_usart.py similarity index 91% rename from demo_ndir_usart.py rename to examples/demo_ndir_usart.py index 2eb9c26..0e98d89 100644 --- a/demo_ndir_usart.py +++ b/examples/demo_ndir_usart.py @@ -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') diff --git a/demo_neo2.py b/examples/demo_neo2.py similarity index 89% rename from demo_neo2.py rename to examples/demo_neo2.py index ab092a5..3e00be7 100644 --- a/demo_neo2.py +++ b/examples/demo_neo2.py @@ -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') diff --git a/demo_neo3.py b/examples/demo_neo3.py similarity index 100% rename from demo_neo3.py rename to examples/demo_neo3.py diff --git a/examples/demo_neopixel.py b/examples/demo_neopixel.py new file mode 100644 index 0000000..5eb8a96 --- /dev/null +++ b/examples/demo_neopixel.py @@ -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]) + diff --git a/demo_nrf24.py b/examples/demo_nrf24.py similarity index 99% rename from demo_nrf24.py rename to examples/demo_nrf24.py index 08bf5a8..3329876 100644 --- a/demo_nrf24.py +++ b/examples/demo_nrf24.py @@ -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): diff --git a/demo_pulse.py b/examples/demo_pulse.py similarity index 66% rename from demo_pulse.py rename to examples/demo_pulse.py index d7a745e..95481a0 100644 --- a/demo_pulse.py +++ b/examples/demo_pulse.py @@ -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') diff --git a/demo_pymodoro.py b/examples/demo_pymodoro.py similarity index 93% rename from demo_pymodoro.py rename to examples/demo_pymodoro.py index 6accd89..322194f 100644 --- a/demo_pymodoro.py +++ b/examples/demo_pymodoro.py @@ -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 diff --git a/examples/demo_transient.py b/examples/demo_transient.py new file mode 100644 index 0000000..8eac4ce --- /dev/null +++ b/examples/demo_transient.py @@ -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") + diff --git a/loratest.txt b/examples/loratest.txt similarity index 100% rename from loratest.txt rename to examples/loratest.txt diff --git a/main.py b/examples/main.py similarity index 100% rename from main.py rename to examples/main.py diff --git a/mat_sampling.m b/examples/mat_sampling.m similarity index 100% rename from mat_sampling.m rename to examples/mat_sampling.m diff --git a/nrf_config.ini b/examples/nrf_config.ini similarity index 100% rename from nrf_config.ini rename to examples/nrf_config.ini diff --git a/show_nparray.py b/examples/show_nparray.py similarity index 100% rename from show_nparray.py rename to examples/show_nparray.py diff --git a/sx_fsk.py b/examples/sx_fsk.py similarity index 100% rename from sx_fsk.py rename to examples/sx_fsk.py diff --git a/test_adc.py b/examples/test_adc.py similarity index 100% rename from test_adc.py rename to examples/test_adc.py diff --git a/test_adc2.py b/examples/test_adc2.py similarity index 100% rename from test_adc2.py rename to examples/test_adc2.py diff --git a/test_dac.py b/examples/test_dac.py similarity index 100% rename from test_dac.py rename to examples/test_dac.py diff --git a/test_freq_cap.py b/examples/test_freq_cap.py similarity index 100% rename from test_freq_cap.py rename to examples/test_freq_cap.py diff --git a/test_ini.py b/examples/test_ini.py similarity index 100% rename from test_ini.py rename to examples/test_ini.py diff --git a/test_onewire.py b/examples/test_onewire.py similarity index 100% rename from test_onewire.py rename to examples/test_onewire.py diff --git a/test_ping.py b/examples/test_ping.py similarity index 100% rename from test_ping.py rename to examples/test_ping.py diff --git a/test_pwmdim_music.py b/examples/test_pwmdim_music.py similarity index 97% rename from test_pwmdim_music.py rename to examples/test_pwmdim_music.py index 1206a6b..44c150d 100644 --- a/test_pwmdim_music.py +++ b/examples/test_pwmdim_music.py @@ -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 diff --git a/test_pwmdim_sweep.py b/examples/test_pwmdim_sweep.py similarity index 91% rename from test_pwmdim_sweep.py rename to examples/test_pwmdim_sweep.py index fbb387a..ad2606b 100644 --- a/test_pwmdim_sweep.py +++ b/examples/test_pwmdim_sweep.py @@ -2,6 +2,8 @@ import time import gex +# pwm frequency sweep + with gex.Client(gex.TrxRawUSB()) as client: pwm = gex.PWMDim(client, 'dim') diff --git a/test_sipo_omicron.py b/examples/test_sipo_omicron.py similarity index 95% rename from test_sipo_omicron.py rename to examples/test_sipo_omicron.py index bf02683..97c4f78 100644 --- a/test_sipo_omicron.py +++ b/examples/test_sipo_omicron.py @@ -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') diff --git a/test_touch.py b/examples/test_touch.py similarity index 95% rename from test_touch.py rename to examples/test_touch.py index 1d82b32..14d7b2b 100644 --- a/test_touch.py +++ b/examples/test_touch.py @@ -2,6 +2,8 @@ import time import gex +# toush sensing test + with gex.Client(gex.TrxRawUSB()) as client: tsc = gex.TOUCH(client, 'tsc') diff --git a/test_dongle.py b/test_dongle.py index 2061ae1..1c61f97 100644 --- a/test_dongle.py +++ b/test_dongle.py @@ -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: