Programming

My run down on the happenings of .NET, PHP, C++, and just about any other language out there.

GCC was here

GNU did that part on the end.

Kudos to Google Books Ngram Viewer – graph link

Posted by admin in Computers, Programming, Random, 0 comments

IRduino

Its been a while since I posted on here, and to that note I should introduce my new project. First a prologue, recently it’s getting hard to use multiple remotes for my various devices. I would like a centralized media control system like the Logitech Harmony or the Google Nexus used to control Google Fiber products, but alas, I have neither. Nor do I have the money and wherewithal to deal with manufacturers that refuse to update their code. So I have decided to roll my own Arduino based remote control.

The project is connected to the local network through an Arduino Ethernet or Arduino + Ethernet Shield. It should in practice be able to send arbitrary IR commands to various devices. It should be configurable though a web interface using the local network as its interface to other devices like a smart phone or web dashboard. Currently this project is not functional as it has just been started but with occasional weekend coding binges it will be completed eventually. Then I will have a fully functional remote control for all of my devices, configurable through the local ethernet or wi-fi. Eventually, it may control itself as I offload more functions to the device. For example, turning on the Xbox will need the TV so it will turn it on too. This project is a work in progress so it will break and probably quite often. If you have cloned the repo and your merge doesn’t work you may have to do a rebase.

You can find this project at: https://github.com/infomaniac50/IRduino.
There are some related projects for this repo. They help with debugging and construction and are as follows:

  1. IRduinoDump: https://github.com/infomaniac50/IRduinoDump
    2. IRduino.NET: https://github.com/infomaniac50/IRduino.NET
Posted by admin in Electronics, Programming, 0 comments

Update to Arduino Random Library!!!

Recently I have been working on the new api for the Arduino Random library. The library now has methods that return different integer sizes from byte to long. I’m not sure if I’ll add long long though as the delay would be too great. This is because the library will block the MCU until it has gathered all of the entropy. If the source of randomness going into the Arduino’s ADC is not very random the library can take a long time to generate the bits. This is especially true of the von neumann debiasing code since it truncates long stretches of ones or zeros.

The library is based on code by Rob Seward albeit heavily modified. Most of the debiasing code remains the same as well as the calibration code. The new code is now up on Github at https://github.com/infomaniac50/Random/. Feel free to fork away and make changes as you see fit. If you use the code please include links back to this blog. I’m sure Rob would like to see some attribution to him as well.

If anybody has any questions feel free to leave a comment, but please, only if you are human.

Posted by admin in Electronics, Programming, 0 comments

Yay!!! New Arduino RNG

Here are the results of the new random number generator I built yesterday.
The old random number generator was not putting out an unbiased stream of bits.
I tried using debiasing algorithms with the old generator but it was not enough.

ent LOGGER00.CSV

Entropy is how random a piece of data is, basically how many random bits are in one byte.
True randomness is 8.0 bits per byte.
We are really close. Yay!!! Five Nines!!! Statistically Significant!!! Yay!!!
Entropy = 7.999993 bits per byte.

Basically says how small you could get it with a zip file
Zip files and pretty much all compression schemes do their job by removing patterned and repeating sequences of bits
Optimum compression would reduce the size
of this 25874432 byte file by 0 percent.

Can’t quite figure out what a good figure is on this test
but 50 percent with an average of 254.05 seems good
Chi square distribution for 25874432 samples is 254.05, and randomly
would exceed this value 50.50 percent of the times.

Do the bytes average out to be in the middle
Tests the ratio of ones to zeros in the bit stream
Arithmetic mean value of data bytes is 127.4920 (127.5 = random).

Can we calculate Pi correctly, if so, we pass. Yay for Pi!!! Yay for Pie!!!
Monte Carlo value for Pi is 3.141568568 (error 0.00 percent).

Assuming this tests byte to byte similarities
Which means is the current byte similar to the last one
Serial correlation coefficient is -0.000016 (totally uncorrelated = 0.0).

True_Random_Logger

Random class for Arduino

Logger class for Arduino

Schematic

The diode is a 12.1V zener and C1 is a ceramic disc type capacitor. The zener diode’s part number is an artefact of the designer I used so you can ignore it.

[svg src=/wp-content/uploads/2012/05/RNG2_schem.svg width=550 height=550]


Full Size

Posted by admin in Computers, Electronics, Programming, 3 comments

Xbox 360 Remote Control with an Arduino

I recently made a neat little gadget with my Arduino Mega that controls my Xbox 360. It uses the remote control codes from the lirc project. I used an old keypad and an infrared led I found at a hamfest. Its works really good for controlling Hulu and Netflix. I used to have to turn the controller on and wait for it to connect when all I wanted to do is pause the video. With this I just turn on the Arduino and press the pause button and the Xbox pauses the video. It is so much easier now to control the xbox. What I would really like to do is turn it into a permanent device with maybe a touch screen and learning capabilities. Then it would be just like one of the logitech 100 dollar remotes. As of right now it runs on my breadboard. The infrared led is controlled with a library from the experimental branch of Ken Shirriff’s IR library. My version of the library also includes the ability to control Panasonic devices. I previously used it to control my 50″ Panasonic. The library uses the pwm output of timer 2 on the arduino, which on the mega is pin 9. Ken’s blog says pin 3 but that is for the Arduino Uno. The circuit includes a transistor because it is drawing more current than a pwm pin can supply. I didn’t have any low value resistors, so I hooked four 220 ohm resistors in parallel. I also modified the Keypad library from the arduino.cc playground to work with my old non-matrix keypad. Both modified versions of the libraries are available on Github here KeypadSimple and here IRremote.

Here are some pictures of it wired up on the breadboard. Click on any of them to get a close up.

 

Posted by admin in Electronics, Programming, 8 comments

Arduino Hardware Random Number Generator

I have been dabbling in cryptography for a while now and recently I got into random number generators. I found out that crypto libraries use random number generators all the time. You would have to be able to keep the output of the library unpredictable to ensure security. They do that mostly with pseudo random number generators. In other words they use an algorithm to generate the random numbers. These algorithms take a seed value to start the sequence and then only go for so long before the sequence repeats itself. So by using a true random number generator you can ensure that the output of the crypto library is kept secure.

I wanted a random number generator for my own use and I came upon a page on Rob Seward’s blog for a random number generator using the arduino as the hardware interface. The board works by taking the noise that you get from running the pn junction in reverse breakdown mode. Then amplifying it through two stages and sampling it with the Arduino’s ADC. I don’t have an oscilloscope so I don’t know what the noise distribution looks like. However, I have collected the random output on a computer and ran it through a basic entropy test. The output of ent.exe from http://www.fourmilab.ch/random/looks pretty good. This was done on a 5MB file so I imagine if I get more samples the chi squared distribution would increase as well.

C:\Apps>ent -b random.dat
Entropy = 1.000000 bits per bit.

Optimum compression would reduce the size
of this 41943040 bit file by 0 percent.

Chi square distribution for 41943040 samples is 0.00, and randomly
would exceed this value 95.89 percent of the times.

Arithmetic mean value of data bits is 0.5000 (0.5 = random).
Monte Carlo value for Pi is 3.141912514 (error 0.01 percent).
Serial correlation coefficient is 0.000081 (totally uncorrelated = 0.0).

Here are some pictures of the peripheral board I put the circuit on.

Here are some pictures of it connected to the Arduino.

Here is the code I used for the Arduino. I made quite a few modifications to it, most notably I transformed it into libraries so you can use it in your own code. The code should be up on GitHub shortly, but if not it means I am still tweaking it.

True Random Logger

Posted by admin in Electronics, Programming, 4 comments

ScriptKey

>

I’m pleased to announce that I have now released a project I have been working on for some time. The program allows the user to write code in C# and hook them input events such as keyboard buttons, mouse events, etc. This project has been quite the learning experience for me. It taught me aspects of .NET Remoting, AppDomains, and compiling code without Visual Studio. Since the user’s code runs in its own AppDomain it needs to have a way to communicate with main application. It does the with the IPC(Inter-Process Communication) mechanism to communicate between AppDomains. The program is not quite complete yet but it is ready for scripting. You can get it at its SourceForge project page https://sourceforge.net/projects/scriptkey/.

Posted by admin in Programming, 0 comments

Visual Studio 2010 Review

I recently downloaded Visual Studio 2010 from Microsoft’s Dreamspark website. After a nearly 2 hour install completed, I promptly opened it up and started exploring.

The first time opened it I noticed that the user interface is drawn with WPF. Now I’m not opposed to this but, the code editor window just doesn’t seem as responsive as earlier versions. This may just be due to the fact that its running on a 4 year old single-core laptop.

The next thing I checked out was the extension manager. With it you can browse for your favorite extensions without opening the browser. It also can check for updated extensions automatically.

In Visual Studio 2008, coding in C# had its downsides compared to VB. For example, Intellisense only triggered when accessing a member and if you did not spell the member’s parent correctly you get nothing. This has been fixed in VS2010. I am now able to type my using statements with ease.

I have not been able to try it with multiple monitors since I only have one at the moment. Although, it does sound like a neat feature.

Overall I do like this new version of Visual Studio. It has some neat features and I’m still exploring.

Posted by admin in Computers, Programming, 0 comments