Skip to main content

Posts

Showing posts with the label python

A Lesson in LoRa Module P2P Standards (or the Lack Thereof)

I got a handful of LoRa modules from Reyax a while back, the RYLR896 model based on Semtech SX1276 chips. Instead of using an SPI interface they operate over UART using a small set of AT commands. This made them easier to work with since I didn't have to dig too deeply into a bunch of SPI registers and Semtech specs and they communicate between one another really well. My Espruino JS module for them is available here , which I've used in a few of my YouTube videos. And more recently I've written a MicroPython module for them here .   (A pair of Reyax RYLR896  modules) But, always being on the lookout for different boards and platforms I eventually ended up with a few Maduino LoRa boards. These are cool because they have an Arduino-compatible ATmega328 and the same Semtech LoRa chip (via an RFM95) both integrated on one board. They weren't compatible with Espruino or MicroPython though, and they used the SPI interface instead of AT commands so I knew I would need to lo...

CircuitPython Game Development (PewPew M4)

Check out this open source CircuitPython game development platform based on the ARM M4 microcontroller. If you're looking to do some homebrew game development on a handheld platform, this is a great option. In this video I give an overview of the hardware itself and show how the CircuitPython programming environment works on it along with some basic programming examples. For more information check out the Hackaday page and the Makerfabs product info page.

Interactive (Touch) Musical Christmas Tree

In this video I should how to build a capacitive touch Christmas tree that allows you to play music just by touching the ornaments. All it takes is a little bit of Python code, a Raspberry Pi, and a Bare Conductive Pi Cap. Get ready to rock around the Christmas tree!

Always Secure Your localhost Servers

Recently I was surprised to learn that web browsers allow any site you visit to make requests to resources on localhost (and that they will happily allow unreported mixed-content ). If you'd like to test this out, run an HTTP server on port 8080 (for instance with python -m http.server 8080 ) and then visit this page. You should see "Found: HTTP (8080)" listed and that's because the Javascript on that page made an HTTP GET request to your local server to determine that it was running. Chances are it detected other services as well (for instance if you run Tor or Keybase locally). There are two implications from this that follow: Website owners could potentially use this to collect information about what popular services are running on your local network. Malicious actors could use this to exploit vulnerabilities in those services. Requests made this way are limited in certain ways since they're considered opaque , meaning that the web page isn't able...

Exploring Sub-GHz Radio With RTL-SDR and GQRX

Today I took a look at some hardware for working with sub-GHz radio transmissions, especially FM. All of which came in a previous HackerBoxes box. My favorite item was definitely the RTL-SDR dongle! I could play around with this thing for hours surfing the radio waves and listening to weird broadcasts. There's even a Python library named pyrtlsdr for working with these devices so you can scan/record radio transmissions programmatically:  https://github.com/roger-/pyrtlsdr Next I'm going to solder together the FM transceivers included in the box and play around with writing Arduino firmware for them. Those things should work similar to the LoRa modules I've been using but they trade in the long range for increased bandwidth. Should be good for streaming data locally and still have much better range than most home WiFi or Bluetooth. Here's a video overview of the hardware included in HackerBox 0034 as well as a demo of the RTL-SDR dongle using GQRX to visually and...

Concurrency on the Internet of Things (Arduino, MicroPython, Espruino)

In this presentation I talk about what concurrency actually is, why it matters for Internet of Things applications, and which platforms are best at handling it.

Running a Python Web Server on a Microcontroller

I built my own RGB smart light that can be controlled with an HTTP API using only a little bit of Python code and a WiPy 3.0 .

Internet of Things Development Board: FireBeetle ESP32

This is an IoT development board for the ESP32 that can be programmed using the Arduino IDE , MicroPython , or JavaScript using Espruino .

Write a Web App in Go

I've recently started a small series of video tutorials with the first one being  Write a Web App in Go . Each tutorial will have its own Github repo here where the commits will be in sync with the tutorials for anyone following along. After this Go tutorial I'm thinking that I'll cover something involving Python3. Maybe a start-to-finish project using flask, tornado, django...? Or just an in-depth tour of a common library like requests, numpy, pandas, or pygame? Any suggestions?

Naive Bayes (and author detection)

I've been playing around with various classification algorithms lately, so I wrote a really simplified discrete naive bayes classifier in Python. No emphasis on sample correction, simplicity was key here, but it still works quite well. from operator import itemgetter from collections import defaultdict class BayesClassifier: def __init__(self): self.total_count = 0 # Observations of individual attributes self.class_count = defaultdict(int) # Observations of cls self.attrs_count = defaultdict(int) # Observations of (cls, attrs) self.correction = 0.0001 # Prevent multiplication by 0.0 def train(self, cls, attrs): ''' Add observation of 'attrs' as being an instance of 'cls' ''' self.class_count[cls] += 1 for attr in attrs: self.attrs_count[(cls, attr)] += 1 self.total_count += 1 def rate(self, cls, attrs): ''' Return probability rating of 'attrs' bei...

Python musical update

Based on my procedural music project I had been working on here . I've made some improvements. Abstracted the playback some, can now play through numpy, oss, or pyaudio. The plan is to default to the best playback method, right now it just uses the first one that seems available. I did this because I got dozens of complaints about using just pyaudio. Can save audio to wave files, other formats would be nice but are not worth my time right now. It's got a few example files to give some idea of usage, but no documentation. Google code project page is up: http://code.google.com/p/python-musical/ Download link: http://python-musical.googlecode.com/files/python-musical.tar.gz Examples include: arpeggiated chord progression randomly generated lead (with chorus effect) basic example of waveform generating If you want to take a listen without running it, I saved the audio output of examples 1 and 2... Example-01.wav Example-02.wav

My new musical instrument: Python

It's still very young, but here is the library I've been working on for generating music in (nothing but) Python . "test.py" is an example of what you can do. The real purpose isn't to code your music out this way, it's intended as a backend for generating / manipulating music. My end goal is a tab-based editor that plays back with this, but I'm going to keep working on this backend and hope some brave snake wrestler comes along and has the itch to write a proper interface (and if that doesn't happen, I'll start on the interface when I feel satisfied with the backend). The Timeline and Hit classes are just ideas right now. I'm not sure they'll stay in the form they are (I'm thinking a guitar-oriented timeline, holding fret/string/amplitude per hit, is more along the lines of what I need). I'm also on the hunt for efficient numpy/scipy implemented effects and sound sources. I've been playing around some with generating Karplus-S...

Procedural music with PyAudio and NumPy

Combining two of my favorite pastimes, programming and music... This is the hacky "reduced to it's basic components" version of a library I've been working on for generating music and dealing with music theory. Tweaking the harmonics by changing the shape of the harmonic components and ratios can produce some interesting sounds. This one only uses sine waveforms, but a square / saw generator is trivial with numpy. It takes a second to generate, so don't turn your volume up too loud in anticipation (it may be loud). import math import numpy import pyaudio import itertools from scipy import interpolate from operator import itemgetter class Note: NOTES = ['c','c#','d','d#','e','f','f#','g','g#','a','a#','b'] def __init__(self, note, octave=4): self.octave = octave if isinstance(note, int): self.index = note self.note = Note.NOTES[note] elif isin...