"When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you"
Here’s a great project Gilberto wrote in to share with us, based on our Learning System tutorial:
Thanks to your excellent tutorial I was able to migrate your Python implementation to C#. I am running mono on the Raspberry Pi and using RaspberryPi.Net library.
You can find his code here. From the software documentation:
The purpose of this library is to provide a Mono.NET interface to the GPIO pins on the Raspberry Pi. All of this code was written using Visual Studio 2010 Express but the goal is to be fully compatible with Mono. This library is written using .NET 4.0 therefore the latest version of Mono (2.10) is recommended. At the time of this update, the Raspbian wheezy 2012-07-15 image installs Mono 2.10.8.1.
The GPIO pins are best described here. They can be accessed in 2 ways, either using the file-based I/O (GPIOFile.cs) or direct memory (GPIOMem.cs) using Mike McCauley’s BCM2835 library which is available here. There is also a GPIODebug.cs class that can be used to test your application without a Raspberry Pi.
Here is a sample bit of code to blink an LED attached to pin 12
Hi! We are Vasilis Georgitzikis, Maria Kousta, Markellos Orfanos, Stelios Tsampas and Dimitris Amaxilatis, and we are the team behind codebender. In the past, each of us has worked on quite a few projects you might know, like MacPorts, Growl, the Arduino TFTP bootloader and we even had a project featured on hackaday. None of it comes close to our work on codebender though.
codebender comes to fill the need for reliable and easy to use tools for makers. A need that from our own experience could not be totally fulfilled by any of the existing solutions. Things like installing libraries, updating the software or installing the IDE can be quite a painful process.
In addition to the above, the limited features provided (e.g. insufficient highlighting, indentation and autocompletion) got us starting building codebender, a completely web-based IDE, that requires no installation and offers a great code editor. It also stores your sketches on the cloud.
That way, you can still access your sketches safely even if your laptop is stolen or your hard drive fails! codebender also takes care of compilation, giving you extremely descriptive warnings on terrible code. On top of that, when you are done, you can upload your code to your Arduino straight from the browser without installing anything.
Over the past 10 years, Processing has become the programming language of choice for anyone making technology art, whether it’s at NYU’s ITP program or the more adventurous corners of the New York Times. We talked with Casey Reas — half of the Processing team and a reknowned computer artist in his own right — about his favorite UI tricks and the upcoming release of Processing 2.0.
For an embedded project I’m working on, I had to implement an algorithm to convert from HSB (hue/saturation/brightness) to 8-bit RGB color values for PWM’ing LEDs. This is what I came up with. It creates a ‘constant brightness’ RGB value: at full saturation (no ‘whitewash’), only two of the 3 RGB colors are on at a time, and their ‘on’ times are mathematically complimentary (though not phase-complimentary) with respect to the max 255 value.
Increasing saturation will increase the overall brightness of the LEDs, but that is to be expected — for a given maximum magnitude, there is more overall energy in white light than there is in light of a particular color. The saturation calculation works by adding a constant ‘floor’ value to all channels. Individual color values are then placed between this floor and the 255 maximum. A saturation value of 0 results in all channels at 100% duty cycle.
The ‘brightness’ is the last calculation performed. It takes a saturation modified hue value, and simply proportions it to the maximum value. So, a brightness of 197 will output light which is ~197/255 of the maximum output value. Naturally, there are losses inherent to integer arithmetic, but it’s close enough for most uses. Further, the linear nature of the brightness control means it is not ‘gamma corrected’ — that would require logarithmic brightness control which, for what I’m doing, is completely unnecessary.
This algorithm uses no sine tables or floating point math, so it’s pretty fast, though it could probably be optimized to use shifts and adds instead of mults and divides. It’s also relatively small. The code itself is in C, so it can be used on most platforms.
Click ‘more’ for the code snippet and just copy/paste into a text editor –
Lauren Ipsum is a children’s story about computer science. In 20 chapters and ~35K words, she encounters dozens of ideas from timing attacks to algorithm design, the subtle power of names, and how to get a fair flip out of even the most unfair coin.
The book is mostly written, and Ytaelena is working on the illustrations and layout. We’ve been working on this project over nights & weekends for about a year and a half. In return for a signed pre-sale copy of the book, your pledges will go towards translating the book into Spanish, Portuguese, and other languages.
This PC emulator is written in Javascript. The emulated hardware consists in:
• a 32 bit x86 compatible CPU
• a 8259 Programmble Interrupt Controller
• a 8254 Programmble Interrupt Timer
• a 16450 UART.
The code is written in pure Javascript using Typed Arrays which are available in recent browsers. It was tested with Firefox 4 and Google Chrome 11 on Linux, Window and Mac (it does not work with Chrome 12 beta. As far as I know, it is a bug in the browser). In any case, a fast Javascript engine is needed to have good performance.
“Invent Your Own Computer Games with Python” is a free book that teaches you how to program in the Python programming language. Each chapter gives you the complete source code for a new game, and then teaches the programming concepts from the example.
“Invent with Python” was written to be understandable by kids as young as 10 to 12 years old, although it is great for anyone of any age who has never programmed before.
This second edition has revised and expanded content, including using the Pygame library to make games with graphics, animation, and sound.
You can buy it or read/download it online CC version.
If you have a lot of button inputs for a project, keeping track of them (whether they’re pressed, just pressed or just released) and debouncing can get a bit hairy. here is some sample code that will keep track of as many buttons as you’d like. The example shows 6. To change the pins or number of buttons, just put them in the array called “buttons” and the rest of the code will automatically adjust. (The code is in Arduino-ese but its pretty much just straight up C)
Enjoy!
#define DEBOUNCE 10 // button debouncer, how many ms to debounce, 5+ ms is usually plenty
// here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etc
byte buttons[] = {14, 15, 16, 17, 18, 19}; // the analog 0-5 pins are also known as 14-19
// This handy macro lets us determine how big the array up above is, by checking the size
#define NUMBUTTONS sizeof(buttons)
// we will track if a button is just pressed, just released, or 'currently pressed'
byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];
void setup() {
byte i;
// set up serial port
Serial.begin(9600);
Serial.print("Button checker with ");
Serial.print(NUMBUTTONS, DEC);
Serial.println(" buttons");
// pin13 LED
pinMode(13, OUTPUT);
// Make input & enable pull-up resistors on switch pins
for (i=0; i< NUMBUTTONS; i++) {
pinMode(buttons[i], INPUT);
digitalWrite(buttons[i], HIGH);
}
}
void check_switches()
{
static byte previousstate[NUMBUTTONS];
static byte currentstate[NUMBUTTONS];
static long lasttime;
byte index;
if (millis() < lasttime) {
// we wrapped around, lets just try again
lasttime = millis();
}
if ((lasttime + DEBOUNCE) > millis()) {
// not enough time has passed to debounce
return;
}
// ok we have waited DEBOUNCE milliseconds, lets reset the timer
lasttime = millis();
for (index = 0; index < NUMBUTTONS; index++) {
justpressed[index] = 0; // when we start, we clear out the "just" indicators
justreleased[index] = 0;
currentstate[index] = digitalRead(buttons[index]); // read the button
/*
Serial.print(index, DEC);
Serial.print(": cstate=");
Serial.print(currentstate[index], DEC);
Serial.print(", pstate=");
Serial.print(previousstate[index], DEC);
Serial.print(", press=");
*/
if (currentstate[index] == previousstate[index]) {
if ((pressed[index] == LOW) && (currentstate[index] == LOW)) {
// just pressed
justpressed[index] = 1;
}
else if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
// just released
justreleased[index] = 1;
}
pressed[index] = !currentstate[index]; // remember, digital HIGH means NOT pressed
}
//Serial.println(pressed[index], DEC);
previousstate[index] = currentstate[index]; // keep a running tally of the buttons
}
}
void loop() {
check_switches(); // when we check the switches we'll get the current state
for (byte i = 0; i < NUMBUTTONS; i++) {
if (justpressed[i]) {
Serial.print(i, DEC);
Serial.println(" Just pressed");
// remember, check_switches() will CLEAR the 'just pressed' flag
}
if (justreleased[i]) {
Serial.print(i, DEC);
Serial.println(" Just released");
// remember, check_switches() will CLEAR the 'just pressed' flag
}
if (pressed[i]) {
Serial.print(i, DEC);
Serial.println(" pressed");
// is the button pressed down at this moment
}
}
}
if you want, you can even run the button checker in the background, which can make for a very easy interface. Remember that you’ll need to clear “just pressed”, etc. after checking or it will be “stuck” on
#define DEBOUNCE 10 // button debouncer, how many ms to debounce, 5+ ms is usually plenty
// here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etc
byte buttons[] = {14, 15, 16, 17, 18, 19}; // the analog 0-5 pins are also known as 14-19
// This handy macro lets us determine how big the array up above is, by checking the size
#define NUMBUTTONS sizeof(buttons)
// we will track if a button is just pressed, just released, or 'currently pressed'
volatile byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];
void setup() {
byte i;
// set up serial port
Serial.begin(9600);
Serial.print("Button checker with ");
Serial.print(NUMBUTTONS, DEC);
Serial.println(" buttons");
// pin13 LED
pinMode(13, OUTPUT);
// Make input & enable pull-up resistors on switch pins
for (i=0; i< NUMBUTTONS; i++) {
pinMode(buttons[i], INPUT);
digitalWrite(buttons[i], HIGH);
}
// Run timer2 interrupt every 15 ms
TCCR2A = 0;
TCCR2B = 1<<CS22 | 1<<CS21 | 1<<CS20;
//Timer2 Overflow Interrupt Enable
TIMSK2 |= 1<<TOIE2;
}
SIGNAL(TIMER2_OVF_vect) {
check_switches();
}
void check_switches()
{
static byte previousstate[NUMBUTTONS];
static byte currentstate[NUMBUTTONS];
static long lasttime;
byte index;
if (millis() < lasttime) {
// we wrapped around, lets just try again
lasttime = millis();
}
if ((lasttime + DEBOUNCE) > millis()) {
// not enough time has passed to debounce
return;
}
// ok we have waited DEBOUNCE milliseconds, lets reset the timer
lasttime = millis();
for (index = 0; index < NUMBUTTONS; index++) {
currentstate[index] = digitalRead(buttons[index]); // read the button
/*
Serial.print(index, DEC);
Serial.print(": cstate=");
Serial.print(currentstate[index], DEC);
Serial.print(", pstate=");
Serial.print(previousstate[index], DEC);
Serial.print(", press=");
*/
if (currentstate[index] == previousstate[index]) {
if ((pressed[index] == LOW) && (currentstate[index] == LOW)) {
// just pressed
justpressed[index] = 1;
}
else if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
// just released
justreleased[index] = 1;
}
pressed[index] = !currentstate[index]; // remember, digital HIGH means NOT pressed
}
//Serial.println(pressed[index], DEC);
previousstate[index] = currentstate[index]; // keep a running tally of the buttons
}
}
void loop() {
for (byte i = 0; i < NUMBUTTONS; i++) {
if (justpressed[i]) {
justpressed[i] = 0;
Serial.print(i, DEC);
Serial.println(" Just pressed");
// remember, check_switches() will CLEAR the 'just pressed' flag
}
if (justreleased[i]) {
justreleased[i] = 0;
Serial.print(i, DEC);
Serial.println(" Just released");
// remember, check_switches() will CLEAR the 'just pressed' flag
}
if (pressed[i]) {
Serial.print(i, DEC);
Serial.println(" pressed");
// is the button pressed down at this moment
}
}
}
If you want to make a clock with an Arduino/Boarduino/AVR, there is a way to hook up a precision 32khz watch crystal
mtbf0 shows you how! pictured above is his LCD clockduino!
Trialex followed up with a really-big-7-segment clock (in the same thread)
I had a bug that caused serial port support to suddenly stop working and there was a corrupt .dmg file so here is a new set of packages with some updates!
Port delay is definable. SpokePOV used to ‘guess’ what the correct delay is but I think it might be wiser to have the user tweak it as necessary
Support for up to 32 banks of memory. What you need so much for I have no idea but hey, its there now!
Windows version now comes with a spiffy installer. Just like Real Software!
Amazon’s S3 (Simple Storage Service) isn’t new, but its certainly gaining traction. Its a wonderful product for people who have a lot of content on their site (images, video, downloads, pdfs) but not a lot of money. Data storage costs $0.15 per GB-Month (prorated), and $0.20 per GB. No minimums, rounded up to the nearest cent.
There are a lot of great providers out there (I use Laughing Squid and highly recommend it) but even LS’s ‘largest’ package is too small for ladyada.net… What to do? Easy: Host all that bulky content at S3, then use mod_rewrite to reroute it over to S3. (You could also do it with php, asp or similar for higher ’security’ but mod_rewrite is lighter and good enough for me)
For example, this image has the url reference “http://www.ladyada.net/images/mintyboost/assemblyv12/inductorusbplace_t.jpg” but if you access that url in your browser, it is automatically rewritten by apache to http://s3.amazonaws.com/ladyadanet_mintyboost/assemblyv12/inductorusbplace_t.jpg
(same with my research pdf, a big pdf that easily accounted for 500M a day of traffic at its peak! http://www.ladyada.net/media/common/thesis.pdf -> http://s3.amazonaws.com/ladyadanet_common/thesis.pdf , S3 doesn’t care what the data is or how its encoded)
Of course mod_rewrite is not necessary, you can always just directly reference s3.amazonaws.com but that makes it harder to move the content around if you decide to eventually go with another service (or if s3 goes away one day!)
OK so, what’s the point and what does this have to do with electronics, eh? Well one of the killer apps of open source and public domain electronics is documentation. That means media. And media storage, backup and transfer is extremely expensive for the everyday person. It becomes increasingly difficult to host a project when one digg-storm or slashdotting makes that ‘free’ webpage account go down.
Edit: I use the Firefox S3 plugin to upload and set the access control on my files.
Are you using S3 or something similar for your projects, kits or documentation? Leave a comment or email! Its always interesting to see what other people are doing in this space.
I finally got around to rewriting the flickrnotes code i wrote to support IE6/7 as well as overlib. Ironically, as a side effect, I had to do this funky opacity thing because in IE you cant have onMouseOver() on an ‘empty’ DIV or SPAN tag unless it has a background color. However, background colors with opacity work just fine.
Hence:
One could always just keep the Opacity 0% and mess with outlines but i kinda got to liking this look.
I fixed some icky problems (in wxMIDI!) and now the MIDIsense software is crosscompiling nicely between Mac and Windows, therefore there is now fast and updated software for both platforms. Rad! Download it now!
If you wanted to try out the MIDIsense hardware but didn’t have a Mac, well I finally finished porting the wxpython code to C++ and its all much faster and more reliable. I also improved the interface and robustness. Try it out and let me know how it goes, available for download from sourceforge