Arduboy noise synth test

IMG_20160510_222525
 

I bought an arduboy, or rather I kickstarter backed it, and yesterday it arrived. So naturally I had to do a little noise synth test on it. The piezo on it is very weak, so the audio in the movie was the best I could capture. Sorry.

This is the source if you want to test it out yourselves

downlad versionIMG_20160510_222525

HelloNOISE.ino download

 

#include "Arduboy.h"
Arduboy arduboy;

 

//counter for sound
float floatI = 0;

float tempo = 0.5;

int currentsound = 4;


void setup() {
 arduboy.begin();
 arduboy.setFrameRate(15);
 pinMode(PIN_SPEAKER_1, OUTPUT);

}


byte sound1(int i)
{
 return i / 13 >> (1 + ((i >> 12) & 3)) | i / 2 >> 2 & (i / 6) >> 7 | i & 31 * i * (i >> 8);
}

byte sound2(int i)
{
 return (i / 3 >> (i % 40 + 5) | i / (24 + i & 3) >> (i % (15 - ((i >> 15) % 8) * 6) + 5)) / 8;
}

byte sound3(int i)
{
 return i >> 2;
}


byte sound4(int i)
{
 return int( ((sin(i * 0.005) / 2.0) + 1) * 127);
}


byte getSound(byte soundtype, int i)
{
 //yes yes, can be done with function array pointers.

 switch (soundtype)
 {
 case 1:
 {
 return sound1(i);
 }
 case 2:
 {
 return sound2(i);
 }
 case 3:
 {
 return sound3(i);
 }

 case 4:
 {
 return sound4(i);
 }



 }
}

void loop() {

 // always write the sound out begore doing or not doing arduboy stuff
 int i = (int)floatI;
 int a = getSound(currentsound, i);

 digitalWrite(PIN_SPEAKER_1, a % 2); //writing the output sound

 floatI += tempo; //float counter so that you can set tempo


 if (!(arduboy.nextFrame()))
 return;


 arduboy.clear();

 for (int x = 0; x < 128; x++)
 {
 int y = getSound(currentsound, floatI + x);
 arduboy.drawPixel(x, y % 64, 1);
 }

 if (arduboy.pressed(A_BUTTON) ) {
 tempo += 0.1;
 }

 if (arduboy.pressed(B_BUTTON) ) {
 tempo -= 0.1;
 }

 if (arduboy.pressed(UP_BUTTON) ) {
 currentsound = 1;
 floatI = 0;
 }

 if (arduboy.pressed(DOWN_BUTTON) ) {
 currentsound = 2;
 floatI = 0;
 }

 if (arduboy.pressed(LEFT_BUTTON) ) {
 currentsound = 3;
 floatI = 0;
 }

 if (arduboy.pressed(RIGHT_BUTTON) ) {
 currentsound = 4;
 floatI = 0;
 }



 arduboy.display();


}

Useless Machine

 

Me and the kids had this idea that we should try and win over the useless machine. It started out as a good interesting idea. The last pair of batteries we had in it lasted a couple of weeks, but that was from time to time use. Not continuos use, and we wanted to try that. How log would it take for the batteries to give up. Would the cameras we have deal with such a long recording. What could we do to avoid cheating. How long would it take to win. Could we even?

Wemos D1, getting up and running os x

I bought a couple of wemos D1's from China. I was hoping for easier to use ESP8266. And they are.

I still had a few snags though. First was that the drivers for the D1 for Mac was to old on the wemos wiki. Secondly 57600 was the correct speed setting for getting me up and running.

Also if you want to get the WeMos D1 to work with
ESP.deepSleep(60000000, WAKE_RF_DEFAULT);
you need to connect D2 to Reset, and then it works.

Took me some time to figure above things out, so I thought I'd better document them here for the search engines to find.

Mechanical Keyboard nerding

Yeah I nerded out, I got into mechanical keyboards when I first found the NeoSans and the open google font tillium, that looked close enough.
I made a watch with that font-face so I could look at it all day.

Photo on 29-05-15 at 08.13

 

But I digress, I'm talking about keyboards here, not DIY watch face makery, that is a post for later.

 

So I found a site called WASD keyboards where you could design your own keyboard, both what color the buttons would have and what could be printed on them. I of course made a design with my favorit font.

Tillium

However, I got critiqued that it looked to real, to much like a product that you could buy in a store. Although I was pleased, I was also displeased because it was correct. I wanted everyone to know that I made it. Also it was kind of pricy so I skipped it. But not after ordering a set of switches from wasdkeyboards.com so I could feel the difference between the different switches.

A month or two later, I needed a new keyboard for my home office, the new screen I had bought and the laptop side by side did not work well together. So I decided to get a bit cheaper keyboard, and I finally ended up getting a Das Keyboard model S. Brown switches. It was a bit noisy but not as loud as I thought it would be. And it was great using a keyboard without any text in the buttons. Then after another month or so I started to get a nagging feeling in my back. Probably because the keyboard had the numeric part, and ergonomically that was not top notch. And also my friend Simon started talking about mechanical keyboards again and he wanted to design his own. After trying my keyboard for an evening he could not go back to the regular keyboard he was using. By this time I really needed wanted a tenkeyless (without the numeric part) keyboard with brown switches, sound dampeners and my own design.

In the video below you will find my final creation, it is a weirded version of the repeating Polynesian lapita pattern.

Yes, it is possible to hire me to do graphical work!

 

 

Johan Larsbys guide to China.

IMG_7068

 

So I've been to China and it was weird, weird and awesome. There are some things that are totally different in China, and some I knew about, and some I had no idea about and had to learn the cumbersome way. I'm collecting these wisdoms here for you dear reader to benefit from.

* Chinese language and english: Chinese is built in a way that is very different from English. No bending of words, so nothing like greener or bigger. In Chinese it would be more green or more big. When I understood this it was easier to understand stuff. "I know" does not mean the same thing in Chinese, it means "Thank you for explaining, I understand now." Not what we might think as "Shut up, I know all this already."

* Food. All I met wanted me to know a lot about China and Chinese foods. Sometimes though, they order "local delicacies" that they wont eat themselves. While this might make a fun story back home I'm not ashamed for skipping a few delicacies that no-one else ate. Always drink water from bottles. Bīng means cold, learn this word. Exercise in front of the mirror your best impression of being cold. Otherwise you will have to drink everything lukewarm.

* Medicin: I had packed several packs of Dimor, a Loperamide that stops with diarrhea. I always had one on my person. One in my backpack. One in my suitcase and one in my toiletry case. Yes I needed to use it. I also packed all other medication I thought I would ever need.

* Internet. Internet in China sucked where I was. Everything is blocked in all of China. Get a VPN service before (if you have gmail or files in dropbox). Then get a backup VPN Service as well, maybe on one of your home computers. And then get a web surfing proxy installed on a web server somewhere

* Taxi. Taxis are scary, get a Uber app (there are several) and get those cabs instead. Much safer. Also, apparently there is no law that requires seatbelt in the backseats of cars. And you get looked at funny if you ask for it in a regular cab.

* Electric outlets. You don't need to worry about it. In the places I've been they have _all_ the standards. Worst case buy a power strip that extends to a lot of different devices. Everything I found was at around 220-230v.

* Toilets, you really need to know (at least in theory) how to use a squat toilet. I did not and apparently (after reading up on the internet) I now know that I used a very hilarious solution. HowTo Link

 

P.S. These advice are not everything you need. Normal stuff, like what is the difference in weather from where you are currently at and all that other stuff still applies.

Wifi enabled mailbox.

Yeah, I built one!

 

So I've been toying around with the ESP8266 wifi chip, and I also hate walking outside to check if the mail has arrived in my mailbox, also this one is old and does not look very nice.

Solution to this partly artificial problem?
Use a ESP8266 to connect to my wifi every time the mailbox is opened, get a php page that downloads sends an email to me with the exact time the mailbox was opened.

IMG_20150726_183258

 

 

I ran into a few snags, battery wise I want it to last forever, and ever. So decided to make the ESP turn itself off, that turned out harder then I thought and I had to get both additional hardware and also help.

First things first though, the ESP8266 is running Arduino, so I thought that buying a https://www.sparkfun.com/products/8904 I could get the esp to tell the pushbutton power switch to turn itself off.  And that worked to a degree. The boot time of EPS was to long and the pin had to be did not have time to change to a correct value so it immediately shut down. It's a latching thing. That is when I got help, Jesper told me that I could make a ramp with a resistor and a capacitor and then he helped me calculate the values.
Long story short, I thought it would work, it didn't, then I got help, and then it worked again.

 

Was the way to my "no dry run utopia" without fail? No. It was actually full of fail. First I made a new mailbox with the kids, in wood. And I used BTLE to communicate from the mailbox. The wooden mailbox did not turn out as stylish as I hoped it would, so I bought the red metal one. BTLE did not reach the house, so that was also useless. Anyways onwards to the pretty pictures and actual code.

 

Hardware:

P1000190

And then transferred to vero board and inside the new mailbox

P1000209

 

 

Arduino code:

#include <ESP8266WiFi.h> 
 const char* ssid = "LarsbyFiber";
 const char* password = "***********"; 
 const char* host = "www.maskelot.se"; 
 int outpin = 0; 
 void setup() {
 
 //Pololu
 pinMode(outpin, OUTPUT);
 //Set digital pin 7 LOW. HIGH turns off the Pololu Pushbutton Power Switch
 digitalWrite(outpin,LOW);
 
 Serial.begin(115200); 
 delay(10); 
 // We start by connecting to a WiFi network 
 Serial.println();
 Serial.println();
 Serial.print("Connecting to ");
 Serial.println(ssid);  
 WiFi.begin(ssid, password); 
 while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print(".");
  Serial.print(WiFi.status());
 } 
 Serial.println("");
 Serial.println("WiFi connected");
 Serial.println("IP address: ");
 Serial.println(WiFi.localIP()); 
 delay(1000); 
 Serial.print("connecting to ");
 Serial.println(host);
 // Use WiFiClient class to create TCP connections
 WiFiClient client;
 const int httpPort = 80;
 if (!client.connect(host, httpPort)) {
  Serial.println("connection failed");
  return;
 }
 // We now create a URI for the request
 String url = "/****.php";
 
 Serial.print("Requesting URL: ");
 Serial.println(url);
 // This will send the request to the server
 client.print(String("GET ") + url + " HTTP/1.1\r\n" +
 "Host: " + host + "\r\n" +
 "Connection: close\r\n\r\n");
 delay(500); 
 // Read all the lines of the reply from server and print them to Serial
 while (client.available()) {
 String line = client.readStringUntil('\r');
 Serial.print(line);

 }
 Serial.println();
 Serial.println("closing connection");
 //Turning off
 Serial.println("Turning off.");
 digitalWrite(outpin,HIGH);
}
void loop() {
 //lol no!
}

PHP Code:

<?php

 $tz = 'Europe/Stockholm';
 $timestamp = time();
 $dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
 $dt->setTimestamp($timestamp); //adjust the object to correct timestamp

 $admin_email = "johan.larsby@maskelot.se";
 $email = "redbox@maskelot.se";
 $subject = "redbox opened at: " . $dt->format('d.m.Y, H:i:s');
 $comment = "";

 echo $admin_email;
 echo "<br>";
 echo $subject;
 echo "<br>";
 echo $email;
 echo "<br>";

 mail($admin_email, $subject, $comment, "From:" . $email);

 echo print_r(error_get_last());
?>

 

As an end I want to show you the wooden mailbox that we ended up converting to a very hipsterish backpack rather then using as a new mailbox. it's available since I have all the backpacks I can use (holds a macbook pro 15")

cropbnackpack

ESP8266 Prankster

ESP8266, it's probably the future of IOT. When I first saw it I thought about my mailbox (will be a later blogpost) and something that makes fun and irritating WiFi networks. When finally the ESP8266 arduino port arrived I made a little program that makes new AP's some with names from a list, and some from existing networks, where the program adds open, free or sucks to an AP it finds when scanning.

In the end it sports a 5vto3.3 step down converter I had from another project, the ESP8266 and some cables.

Tomorrow I'm going to deploy it somewhere.

Prankster

IMG_20150430_180816 (1)

Programming the ESP.

IMG_20150505_210851

Testing with a step down power converter

IMG_20150505_213630

Final prankster, ready to be hidden somewhere

 

#include "ESP8266WiFi.h"

String names[] = {
  "affischering förbjuden",
  "ektoplasma? nä snor!",
  "enarmad, men ambidextriös",
  "arla förmiddag",
  "trippelbarmad",
  "bestefar kan inte simma",
  "bortklemad pågatös",
  "tösapåg med råg",
  "debil gerbil",
  "dissonans med diskreptans",
  "ekivok",
  "ekolali ekolali ekolali igen, flera gånger",
  "embar spann hink",
  "eskalera Eskalera ESKALERA",
  "postmortisk exhumering",
  "refektorium",
  "fekalier",
  "omvändbar reversibel = anagram?",
  "tvehågsen beslutsofattare",
  "ligga på åga",
  "ett slags skrin",
  "didaskaleinofobisk rektor",
  "trollbur"
};

void setup() {

  Serial.begin(115200);
  Serial.println("starting");

  //without this in setup it hung.
  WiFi.disconnect();
  delay(100);
}

void useAMadeUpName()
{
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);
  int nameNum = random(23);
  String APname = String(names[nameNum]);
  WiFi.softAP(APname.c_str(), "", 1);;
  Serial.println(APname);
}



void modifyExistingApName()
{
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  int n = WiFi.scanNetworks();
  if (n != 0)
  {
    int randChooser = random(3);
    int randNetwork = random(n);
    if ( randChooser == 0)
    {
      String APName = WiFi.SSID(randNetwork) + String(" SUCKS!");
      WiFi.softAP(APName.c_str(), "", 1);
      Serial.println(APName);
    }
    else if ( randChooser == 1)
    {
      String APName = WiFi.SSID(randNetwork) + String(" rules!");
      WiFi.softAP(APName.c_str(), "", 1);;
      Serial.println(APName);
    }
    else if ( randChooser == 2)
    {
      String APName = String("open") + WiFi.SSID(randNetwork);
      WiFi.softAP(APName.c_str(), "", 1);;
      Serial.println(APName);
    }
  }
}

void loop() {

  int a = random(1);
  if (random(2) == 1)
    useAMadeUpName();
  else
    modifyExistingApName();
  delay(random(50000) + 1000);
}

Leaving and starting.

Today is the last day of my six month parental leave. I've changed a lot of diapers, fed a lot of meals and I have had the time of my life. Getting to know my youngest daughter and also being at home when the two older kids where finished with school have been wonderful. I have had freedom and purpose at the same time and it felt great.

But today is the last day of that. Tomorrow my little girl will start going to daycare and after the ease-in period is done I must again fill my days with code and emails. But not at BlackBerry where I was when I started out on this adventure. No I will be self-employed, working with casual gaming. I will make less money (at least at first, knock on wood etc) but I will have more freedom to manage my time so I can continue to pester my kids being a dad that knows what they are doing. Being a dad that finds the weird tv-shows and watches ALL THE EPISODES with them.

Wish me luck.