Blogs
MQTT Publisher and Subscriber in Scala with Eclipse Paho
MQTT is a lightweight publish-subscribe protocol widely used in IoT and telemetry because it runs fine over slow, lossy networks. This post builds a minimal publisher and subscriber in Scala using the Eclipse Paho library, talking to a local Mosquitto broker. The complete code is on GitHub.
How MQTT works MQTT uses a central broker. Publishers send messages to topics, and any subscribers listening to a matching topic pattern receive them. Topics are hierarchical strings separated by /, for …
Continue Reading
: MQTT Publisher and Subscriber in Scala with Eclipse PahoBlogs
A Web Paint App with Flask and MongoDB
Schema-less, document-shaped data like freehand drawings is a good fit for MongoDB: there’s no rigid table to design around stroke coordinates that vary per drawing. This post ties the canvas front-end to a Flask backend that persists drawings in MongoDB.
How the app works The user draws lines, rectangles, or circles on an HTML5 canvas. Each shape is stored in a JavaScript object with its coordinates and colour. When the user clicks “save”, the frontend POSTs the entire drawing …
Continue Reading
: A Web Paint App with Flask and MongoDBBlogs
HTML5 Canvas Paint Application with JavaScript
A small browser-based drawing tool built on the HTML5 <canvas> element and plain JavaScript.
How it works The page contains a <canvas> element that listens for three mouse events: mousedown, mousemove, and mouseup. When you press and drag, the handler draws the currently selected shape (line, rectangle, or circle) in the chosen colour. A toolbar above the canvas lets you pick the tool and colour.
All drawing state lives in the browser; nothing hits the server until you explicitly …
Continue Reading
: HTML5 Canvas Paint Application with JavaScriptBlogs
A Simple CUDA Program: Squaring 64 Numbers on the GPU
Following on from my introduction to parallel programming, this post walks through a simple CUDA program that computes the squares of 64 numbers on the GPU. The source is on GitHub.
A typical GPU program A typical CUDA program follows four steps:
CPU allocates storage on the GPU CPU copies input data from CPU to GPU CPU launches kernels on the GPU to process the data CPU copies the result back from GPU to CPU Compiling 1nvcc -o square square.cu Instead of the regular C compiler, we use nvcc, the …
Continue Reading
: A Simple CUDA Program: Squaring 64 Numbers on the GPUBlogs
Introduction to Parallel Programming
This post focuses on parallel computing on the GPU. Parallel computing solves large problems by breaking them into smaller pieces and running those pieces at the same time.
Why GPUs for parallel computing Modern processors are made from transistors. Each year those transistors get smaller. The feature size is the minimum size of a transistor on a chip. As it decreases, transistors get smaller, run faster, use less power, and you can fit more of them on a chip, giving more resources for …
Continue Reading
: Introduction to Parallel ProgrammingBlogs
Building a Simple Game with HTML5 Canvas and JavaScript
HTML5 introduced the <canvas> element for 2D drawing: a rectangular area on the page that JavaScript can paint into. This post walks through building a simple bird-shooting game using canvas drawing, setInterval timing, keyboard events, and basic collision detection.
Add a canvas element to the HTML document:
1<canvas id="Canvas" width="800" height="450"></canvas> To draw inside the canvas, use JavaScript. First find the canvas element using …
Continue Reading
: Building a Simple Game with HTML5 Canvas and JavaScriptBlogs
Measuring an RC Time Constant with an ATmega8
The time constant of an RC circuit equals R * C (in seconds). It is the time for the capacitor to charge through the resistor to 63.2% of the supply voltage, or to discharge to 36.8% of its starting level.
Approach The ATmega8’s ADC samples the voltage across the capacitor continuously. A digital output pin (PB0) supplies the input voltage to the RC network. The moment PB0 goes high, Timer1 starts counting. When the ADC reading hits 63.2% of the rail (roughly 161 out of 255 for a 5 V …
Continue Reading
: Measuring an RC Time Constant with an ATmega8Blogs
Running Arduino Code on a Standalone ATmega8
An Arduino board is essentially an 8-bit Atmel AVR microcontroller with supporting components for easy prototyping. If you have a bare ATmega8 and a USB ISP (like a USBasp or USBtinyISP), you can skip the board entirely and flash sketches straight from the IDE.
What you need A bare ATmega8 chip A USB ISP programmer (USBasp, USBtinyISP, or similar) The Arduino IDE (version 1.0 used here; later versions work too) Optionally, an 8 MHz crystal if you want to use an external clock IDE setup Download …
Continue Reading
: Running Arduino Code on a Standalone ATmega8Blogs
How to Build a USBtinyISP: Low-Cost DIY AVR Programmer
Atmel AVR chips power a lot of hobby and embedded projects, small, cheap, well-documented. To get code onto them you need a programmer, and commercial ISPs run $20-$40 for something that’s basically an ATtiny running open-source firmware. The USBtinyISP flips that: it’s a DIY programmer built around an ATtiny2313, costs a few dollars in parts, and works with almost any AVR target (ATtiny, ATmega, etc.).
This post walks through building one.
Continue Reading
: How to Build a USBtinyISP: Low-Cost DIY AVR Programmer