A Simple Noise Generator

When I cannot make progres on my “official” projects, I like to try new things, experiment new techniques with simple devices (some complete posts on my other projects will come soon).

After some talks on the Electrolab hackerspace Mailing list, I had the idea to try random number generators. I came across this idea after realizing that good “really random” numbers are of extreme importance for online security, as they are used in SSL, GPG, and lots of other security algorithms.

There are two random number generator categories:

  • Deterministic or pseudo-random number generators
  • Non-deterministic or true random number generators

Pseudo Random Number Generators (PRNG)

With a PRNG, one get new random numbers from algorithms, batch after batch, by applying a given cryptographic primitive to the previous generator output. These generators can rely on encryption (AES, DES) or hashing (SHA, MD5) or other methods. Another method does not use cryptograpy but simple linear congruence relations (usually introducting specific constant values, and a modulo operation with a prime number). What these generators achieve is “deep bit mixing”, and all the mixing operations are based on the initial value used in the algorithm, the seed.

For every seed entered in the algorithm, it will produce a (hopefully) different, but unique, mixed sequence. Using twice the same seed will produce twice the same sequence, hence the deterministic name. The current system time in milliseconds is a classical seeding mechanism, since it will be different at each call, difficult to predict, and never repeat.

With well-chosen algorithms, the numbers (or stream of bits) produced usually have good randomness characteristics. But it is sometimes difficult to prove that the random sequence will never repeat, and that the bits faithfully represents a random variable with correct statistical properties. And in all cases, the produced bits only depend on the seed, which is not often desirable, since an attacker may control this seed and gain the ability to repeat the “random” sequences.

True Random Number Generators (TRNG)

A TRNG relies on a physical phenomenon to produce random values. Some examples include:

  • Voltage across a (high-value) resistor: this is thermal noise
  • Analog to Digital converter noise – conversion uncertainty (this method is used in the FST-01 and the NeuG project)
  • Avalanche and Tunneling noise in a PN juction (diode, transistor) in breakdown conduction mode
  • Atmospheric noise produced in the ionosphere, can be acquired by an FM radio receiver tuned between stations (this is the method used by the random.org website, (which I don’t like it because it can be attacked by transmitting signals on the tested frequency, which has to be kept secret. Of course alterations in randomness will be detected, but this amounts to a denial of service attack)
  • etc.

These generators usually rely on an analog core. A Schmidt Trigger gate can be used to produce a digital data stream with randomly spaced edges. A simple microcontroller will then be able to sample this signal, and deal with it in software.

It is then necessary to:

  • Cancel any generator bias with a “cleaning” algorithm such as the Von Neumann one, that will get raw random bits in pairs, and discard pairs where both bits are equal. This means that the data throughput of such a generator is not constant.
  • Make sure that the random properties of the signal are enforced. Mean, variance, autocorrelation, stuck bits and repeated patterns have to be checked for in real time.
  • Emit data in a usable format (usually a serial data stream)

Some conclusions can be drawn:

  • One has to make sure of the quality of the noise to get sufficiently random numbers
  • The random data throughput is not unlimited! But many RNG can be coupled to used to increase it.

A first device

To apply these concepts, I decided to start with a small basic project : a noise generator. Lots of designs are available on the web, I decided to use a P-N transistor juction, just like this one:

Noise Generator Schematic
Noise Generator Schematic. Source: David Eather, Silicon Chip Online, 2005 ( http://archive.siliconchip.com.au/cms/A_103659/article.html )

Yes, the collector is not connected! This isn’t a mistake! Only the B-E junction of this transistor is interesting. It is biased at 12V, which is over the maximum VBE voltage from the datasheet. This does not destroy the transistor, but produces avalanche and tunneling conduction, which amounts to noise. A simple diode could have been used, but it would have required a much higher voltage, since diodes are designed to sustain high reverse voltages.

Here is a picture of the build:

Noise generator #1
Noise generator #1 – Photo by Sebastien F4GRX

This is one of the simplest circuits I’ve ever built.

For the 2N2222A, the VBE max is 6V, so 12V are enough to produce noise from the BE junction. The generated noise has a 1V peat-to-peak amplitude, which is a correct value for injection into my PC sound card. When listening to that signal, one will hear the classic “psssshhhh” hum, just like the signal between 2 radio stations. Here is a spectrum diagram produced by Audacity:

Generated noise (linear frequency scale)
Generated noise (linear frequency scale)

All audio frequencies are present in this signal, which is a characteristic of “white” noise, just like white light contains all wavelengths. In the high frequencies, I’m suspecting a decrease of amplitude due to filters in my soundcard, and in the low frequencies, we see a lower amplitude, probably caused by interstage capacitors and the soundcard DC-block, however there are a few peaks. Here is the same spectrum with a log horizontal scale, which produces a zoom on the lowest frequencies:

Generated noise - Log frequency scale
Generated noise (Log frequency scale)

All is not so good! All of these peaks are multiple of 50Hz, which is the mains frequency here. So I’m picking up noise from the power supply! The unconnected collector transistor lead may also be picking signals.

This is very bad for random signals, because this basically means that my random data is mixed with a few pure sinusoidal signals, which means that a part of the signal repeats itself every 20 ms. This repetition is easily noticed on an autocorrelation plot, which characterizes similarity of a signal with a delayed version of itself:

Autocorrelation Plot for the generated noise
Autocorrelation Plot for the generated noise

According to the autocorrelation plot, this signal is not random at all. This is just a very noisy sinusoidal signal!

Here is what I plan to do for the future of this project:

  • Shielding the noise generation transistor so that the collector lead does not pick up ambient signals. Also, shielding the whole generator so that no part of the device picks up noise too.
  • Use a battery to power the generator, and do more measures, to check that the 50Hz noise really comes from the power supply.
  • Optimize inter stage capacitors to make sure the noise bandwidth is as wide as possible
  • Add strong power supply filtering to cut off external influences. This will be a very,very low pass filter, with a series association of a low value resistor (in fact, as high as possible to avoid heat, provide sufficient voltage to the transistor, while keeping the filter cutoff frequency as low as possible) and a choke inductance, followed by several bypass capacitors to the ground, in a paralle association of multiple components from picofarads to hundred microfarads.

To conclude, this was a fun experiment. I feel that some simple optimizations will bring me a clean noise generator, that will be able to enter the construction of a reliable true random number generator. I have lots of ideas, but for the moment, 3D printing is calling me!

Update Sep 19, 2013:

Jon remarked that the sound card acquisition could be the cause of the 50Hz Signal, so I made a new recording with audacity, with the same noise generation device attached, unpowered. Here is the result:

Signal résiduel de la carte son
Signal résiduel de la carte son

Yes, that’s a very nice and strong 50 Hz hum 😀 The harmonics are generated by a combination of this signal with the noise generator. Time to drop this sound card if I want to continue serious measurements… Thank you, Jon!

Photo by Sebastien F4GRX

Some packages received !

Aaaand it’s done. I have it. I received my eShapeOko. The only thing now that prevents me from mounting it is the threading of makerslide holes; this will be done on tuesday evening by my very good ham friend F1BHY. Many thanks to him, I’m very grateful for its dedication for his friends.

Pièces eShapeOko
eShapeOko parts

I also received new TRF7970 samples from TI. These are using QFN packages, and it’s quite complex to solder them properly the first time. Last time, I added too many solder paste and I ended up with components floating in a sea of fused solder. I could remove most of the surplus solder, but I fear that these components are short-circuited between the package and the PCB (only X-ray analysis could confirm that), and if they are not, I fear that I fried them with the hot air rework station.

These components will take place on a SeeedStudio board, which has tinned traces. With my previous experience soldering these components, I now believe the small solder quantity already present on the board is enough to solder the components correctly. All I need is flux, which I did not have before.

When it compares to QFN, soldering TQFP packages (for the ARM chip) is a piece of cake 😀

Now that I have a machine to work on, I’ll update you more often. Please note that I also started a build log at the ShapeOko forum. This forum is really interesting and contains a lot of wisdom, interesting upgrades and information about what to do and avoid. One of the most interesting mod is the replacement of the normal Z-axis screw by an “acme screw” with a trapezoidal screw profile. This sort of screw has a larger pitch, so the Z moves can be accelerated, which has a positive influence on the global speed of the machine (the Z axis limits the achievable speed on all other axes).

[eShapeOko] First motor steps!

In the last days, I spent all my free time on my CNC project, on the road to a 3D printer. I realized that the eShapeOko would not have enough room on the Z-axis to allow me to print big 3D objects, so I will continue on this project with the CNC goal in mind, and then, I will consider the 3D printer I build out of it as a “repstrap” (bootstrap printer) to build a full reprap later. Here is a list of items that I already marked as “done”. I still have a Project sheet to track my actions, and all goes as planned. Here is the planning as of August 25.

  • I received the stepper motors.
  • I ordered and received the stepper drivers from Pololu (model DRV8825).
  • I got back the Arduino Nano i had lent to @hugokernel .
  • I managed to compile the grbl firmware for the atmega328, then to upload it in an arduino (that was easy, but I had never done that before. Thanks to @Skywodd and others on Twitter for their precious advice!
  • I completed the wiring for the driver board.

And to complete this electronics step, I tested the board on Sunday afternoon. The board works as expected, no glitch, no wiring error. And the motors are now spinning in response to g-code commands! Here is a small action video of the board:

Not very sexy, but you can see the putty interface to grbl via serial port, the motors accelerate, spin, and slow down. I wired everything on a veroboard (pads and holes), so the wiring process was very fluid, with plenty of space to lay out copper tape for power buses and wirewrap wire for logic signals. I still have room for the spindle controller (just a big MOSFET I think).

Well, that means I’m ready to control a 3-axis CNC! I still had time this afternoon, so I added a second hand Lantronix serial-to-network bridge, so that I can connect to the board via Ethernet. This will be very useful given the position of my CNC in my lab. This also means that any computer in the house will be able to command the CNC, even without a short USB link.

eshapeoko controller recto
Controller board, comoponent size.
eshapeoko controller wiring side
Controller board, solder side. I used copper tape and AWG30 wirewrap wire.

One last important thing: the Pololu modules HAVE TO be tuned for the correct current. When they ship, the variable resistor is in its default position with a taper at 50%, which means a 1.7 Volt reference voltage, which translates into a 3.5 A chopping current. This is too high for most motors, and without the 2A fuses on each one, I would not have known it, with a risk to burn both motors and drivers.

[Project] My CNC / 3D Printer

Okay, the circuits for the NFC module have been sent to SeeedStudio, thanks to them for their efficient and good service: they still remember after one year that they had forgotten to send me a part, and just added that free of charge to my order!

Before the PCB come back, I have a little free time. In the train, instead of playing with kicad, I can make progress on my ebook for french beginners, but I also want to start a big project, something that will be very useful for me in the next years:

I need a 3D printer.

No, what I really need is a CNC router.

No, really, I can’t make my mind.

So both it will be.

I have choosen the eShapeOko. This is a good platform, not so expensive, quite robust with the correct options, and universal. I will be able to convert it from router to 3D printer, to laser cutter, to anything I want, by just swapping the spindle. I will start with a dremel tool, but I’ll then build an extruder and a laser head.

I’m aware that it’s a big project. At the Electrolab Hackerspace, I see lots of people spending a lot of time to ajdust their printers before they can print anything serious. I know that a lot of work is waiting for me.

But that’s okay, with my DIY ambitions, robotics, and such, having a rapid prototyping tool at home will be invaluable. I will choose all the good options available with the eShapeOko kit, so that I get the most robust machine. I want to be able to work wood, plastics, and maybe aluminium, even if this requires the minimum speed.

I’m also ready to make this machine available to my maker friends that need to print and route things. I’m not ready for that yet, but I know that giving a hand to my friends is what I want to do.

Here is what I will buy after I get my birthday present (:D) :

  • eShapeOko kit with options: double x axis, double y drive, extended length, nema23 motors
  • 4 nema23 motors (now ordered)
  • Pololu motor drivers hooked to an arduino to run grbl
  • A Raspbery might be introduced somewhere.
  • The spindle will start with my current dremel tool, that will be ok for wood carving and cutting.
  • A work table, probably 50×60 cm, made with thick wood and everything required to store the unused spindles and accessories.
  • A plexiglas case, to prevent the dust from going everywhere in our flat. And a vacuum cleaner port…

This setup will allow me to cut and drill MDF boards, which is the target number one.

Later, I will pursue target no. 2: 3D printing, which will require a lot of additional work and parts:

  • hotplate
  • extruder with mounting option that will fit where the spindle goes. I plan to hook it to the main Z rail. I will probably ask some help to my friends at Electrolab.

I already have additional ideas: a more powerful spindle to mill aluminium, gearboxes to increase motor torque and resolution, I will have more!

Of course I will share all the next steps with you here. Let’s get to work!

[Project] Hackable NFC module

NFC (Near Field Communication) is a contactless communication technology used for almost all contactless things, transit cards and (recent) contactless bank chip cards to Nabaztag rabbit tags. The radio signal is modulated on a 13.56 MHz carrier, which is an ISM band, just like the wifi 2.4 GHz or sub-GHZ 433.92 MHz. Apart from NFC, this frequency is used for RF plasma technologies, used in Physics, semiconductors industries, etc.

I noticed a lack of hackable and usable NFC devices.

The only one I know is OpenPCD, which uses an NXP contactless frontend, without NFC capabilities. This project is therefore an experimental contactless card reader, with hackable firmware and card emulation capablities (at least, the datasheet says so).

I recently noticed the TRF7970A from Texas Instruments, which is not only able to work just like the NXP chip (card reader mode or “initiator” in NFC slang), but also to use the “peer to peer” and “target” modes, with possible card emulation. The chip is packaged in a damn small QFN, but it’s really worth evaluating, because of its availability and functions. An evaluation board is available from TI, but 1) I don’t like canned evaluation kits, 2) it’s quite expensive and3)  its antenna is not really suited for card emulation. So I’m building my own board.

By RTFMing all reference documentations from TI, I was able to develop my own evaluation card, in a 5×5 format suitable for SeeedStudio manufacturing.

The first board is an suitable loop antenna with 50-ohm matching circuitry as recommended by the app notes. The components values will be deduced from (magic but provided) formulas, but this requires measuring the antenna inductance using a network analyzer. I will come back to this chapter later.

Schéma antenne
Antenna board schematic

This antenna uses a design by NXP with multiple turns. This allows me to get a very symmetic, low capacity antenna (traces are spaced apart, just follow them!) with the connections on the same side of the loop.

Circuit de l'antenne
Antenna PCB

The second board is the core of the reader. It has a matching section to adapt the NFC driver amplifier to the 50-ohm coax wire to the antenna board, the TRF chip, an SPI link to a Tiva C microcontroller, the same kind as what is used on the Stellaris Launchpad boards. Here are some specs:

  • Texas Instruments TRF7970A NFC frontend
  • UFL Coaxial Connector to the antenna
  • ARM Cortex-M4 Tiva C Series TM4F123 Microcontroller
  • 256k flash
  • 32k RAM
  • Device USB port (OTG not wired, I’ll play with that somewhere else)
  • I2C port (would enable simplified control via another microcontroller)
  • UART
  • JTAG port on 10-pins 1/10″ header (standard ARM pinout)
  • 20 available GPIOs on a 1/10″ pitch header
  • 5V power input, via USB or external supply
Schéma frontend NFC
NFC frontend Schematic


PCB Frontend NFC
NFC Frontend PCB

I managed to severely limit the number of PCB traces on the copper side, so that the ground plane is uninterrupted on the whole bottom of the board. This is important for thermal dissipation and noise immunity.

In the next week, I will send both circuits for manufacturing at SeeedStudio, I will have 10 of each. If you are interested to build this project, please ask me, I can sell a set to you if you promise to build it, use it, and not let it collect dust in a drawer…

On the build difficulty side, this board has a TQFP chip (easy to solder) and a QFN one, which is not very friendly. I have access to a hot air station via a friend, that will be very useful to solder the bottom thermal pad. If you’re a hacker, you can solder that with a fine-tip soldering iron.

On the software side, I know that it will take a long time to get a decent reader firmware. I hope to get some help with the coding. I plan to release the software as open source, as well as the hardware, as soon as I have proved that the design works. On the radio side, the Internet is full of interesting documentation.

The low level libs will be based on my current freestella project, that I will publish as well when I start working on this software. At the moment, I have CPU init, GPIO and UART core running fine.

I’ll continue to communicate on this project as it evolves, both here and on twitter.

Now please tell me your thoughts: what would you do with such a device?

Code::Blocks 12.11 Released!

Code::Blocks 12.11 was released yesterday!

Code::Blocks is a very lightweight and easy to use IDE. You can use it with a large number of different compilers. I’m using it daily with:

I’m strongly recommending it to you if you’re in search of something lighter than Eclipse.

You can download it on the project page.

And here is the official forum thread.

Code::Blocks main UI
Code::Blocks main UI


MOD music player on the StelPad

Do you know MOD music?

It’s a lightweight music format, intermediate between sampled/recorded music (MP3, WAVE) and synthetized sounds like what you find on the GameBoy and other old school game consoles. The file contains sampled sequence for each note, and the mod player plays them in sequence according to rules. This avoids a lot of redundancy for similar notes. This sort of music was very successful when computers were not powerful enough to play fully sampled music.

And now, this guy made a MOD player for the stellaris launchpad!

Congrats to Ronen K. !

Source : Hackaday


Something is coming…

These last days I spent a lot of time writing low-level code for the Stellaris Launchpad.

I made progress, I could understand all the details required for the board and CPU startup.

I’m not publishing anything yet, since it’s not even alpha quality. Everything is a mess for the moment, I need to split things in separate files, add comments, etc. But I plan to release my code as soon as possible.

And now, I had to find a real use for this board. I have several ideas for this.

The first step is to get a hardware platform that I can hack to add components, solder, etc.

So here it is. I found a small part of veroboard in one of my drawers, and two in-row connectors, so I hacked a quick vero board booster pack! The total cost is zero, since I already had “everything”.

Here are some pictures, obviously I now have to add components on that 🙂

Veroboard Booster Pack
Vero board booster pack Top view

On the bottom side are the connectors, it’s a bit tricky to solder them, I did it while they were plugged in the board, and I used a flat surface to have them just on the right position while I soldered them.

Veroboard booster pack Bottom view
Veroboard booster pack Bottom view

And now I suggest that you subscribe to the RSS feed to see what I’ll do next.

Let’s make an audio switch

Today we’re building a little device to help my spouse, she’s a piano composer, and she’s recording tracks at home using the audio out of the piano.

The requirement is simple: we have only one speaker, and she wants to switch it between our computer and the piano audio output without playing with the wires.

So we’ll wrap some jack sockets and manual inverters in a small box. I’m doing a dual model so that we can switch something else between two other devices. So that’s 6 sockets and two switches.

The first step is drilling the box for all the connectors. I used scotch tape to let me draw on the box without having problems to erase the drawings later. That way, I can draw as many lines as I want, drill the box at the proper places, then remove the tape. Here we go, that’s the preparation for the box cover:

Audio switch : traces de dessins
Drawing on the tape.

Here I removed the tape:

Audio Switch: perçages
Once drilled, tape is removed.

Now we can go ahead with the connectors, inverters and their wiring.

A small note about the wiring: That’s quite easy to turn wiring into a mess, spaghettinam style. But this time, I wanted to do that wiring properly, by strapping them in a “runway”. This is an old method to achieve proper wiring, you can see that in old radio receivers. Here, the wires were strapped using cotton string covered with some grease, to prevent the string from getting out of place.

I don’t have greased cotton string, so I used thin wrapping wire. Here is the result, at least that’s better than random wires:

Audio switch: câblage en faisceau
“Runway” wiring is better than random.

The jack sockets are screwed in the holes, but that’s not very strong, since I did not have the proper drill bit size, and used a round file to fix the drillings, which resulted in pretty random hole sizes. I used some “Araldite” epoxy glue (mixing resin and hardener) to glue the sockets to the cover, since “Super-glue” (cyanoacrylate) does not survice insertion/removal mechanical shocks very well. Araldite glue needs a lot of time to cure, but the result is extra-strong.

Audio switch: collage des connecteurs
Araldite glue was used to ensure mechanical strength for the jack sockets.

And here we go! Once closed, no one can know my effort about the proper wiring, but that’s okay! I’m hapy with my runways!

Audio switch: terminé
Le switch terminé, avec un jack branché.

The last step will involve labelling the sockets, but before that, my darling will test it, and tell me how she wants to use it!

Bunnie Huang got the 2012 EFF Pioneer Award

Bunnie Huang is, for me, a “great hacker”. He is an achiever, and his achievements have a great impact on Internet communities. He first became known when he released lots of informations about hacking the XBox console, and since then, he published a number of astounding projects, including the Chumby, a connected screen to display just anything without a full desktop computer running, the NeTV, a box to transform any TV screen into a smart TV, that he also used to implement a man-in-the middle attack on protected HDMI links. He’s also known for having designed an easily reproduceable Geiger counter to help people in Japan and elsewhere monitor (and globally share) radiation levels around them, without having to rely on biased information sources.

Beyond that, even if I don’t know him personnally, I have seen several inteviews about him (MAKE, Dangerous Prototypes), and I really like his state of mind. He’s only interested by the technical side of things, and he’s eager to share his knowledge, and he does that very well. This is very important, because it gives a broader reach to his project. I’ve always thought like that, but communicating efficiently is easier said than done. That’s why I’m quite impressed and inspired by him.

Now, let’s talk about the EFF. The Electronic Frontier Foundation (Wikipedia page) is an NGO promoting and defending electronic freedom, specifically when it’s related to the Internet. It has lawyers and personnel willing to assist hackers or other people when they’re unjustly bothered by some justice issues, related for example to the DMCA, patents rights, or free speech (see here for a list of cases).

The EFF also awards a prize to people it thinks has done outstanding work for the sake of electronic freedom. That’s what Bunnie Huang got this year, as an awesome recognition for all he has done for electronic freedom. Congratulations!

So now that you know everything, don’t wait a second before reading the article he wrote about that, and after that, just take a tour of his blog, it’s worth the time!