Change Raspberry Pi lost password

Too much on a hurry when I choose my Raspberry Pi password, and I wrongly noted it. There is a way to reset the pi user password.

  1. Insert the card in your Mac SD card reader (must work on Window too);
  2. Edit the file “cmdline.txt” and append “init=/bin/sh” (thanks Joe Schmoe). The Rpi will boot in single user mode;
  3. Insert the card in the RPi again and boot up;
  4. When prompt available, enter “su” to log as root (with no password);
  5. Type “passwd pi” and enter a new password;
  6. Remember the new password;
  7. Remove the appended string in the “cmdfile.txt” file. Voila!

If you need a password for the root and you don’t have it either, edit the “/etc/shadow” file and replace the root password with a asterisk. Then it will be no password for the root user. (not tested yet).

Noiseless actuators

I finally manage to find a way to make actuators that are enough powerful, small and the most important, noiseless. Since this robot will move all day long, it is essential not to hear it. I tried three types of motors: servos, DCs and steppers. It is not a secret for everyone, theses servos are terribly noisy. The gearbox of miniature DC motor I tried next is too noisy too. At last, I ordered a small stepper with a gearbox and it will be the one selected for the task. So I will replace the three servo motors with these steppers connected to a threaded rod that will move the swash plate.

I’ll have to 3D print some parts to fit all this together, but the essence is there. Now I have to learn to CAD.

There are the two motors, the stepper and the small geared DC one

Small step motor and miniature geared DC motor

Testing the small step motor

Testing the small geared step motor

Looping without breaking the code with the Millis function

Has I also use my blog as a reference for myself, I mainly put this there for further reference. I usually use this lines of code to loop without stopping other functions from being executed or to time certain events.

void myFunc()
{
	unsigned long interval = 60 * 1000; // 60 seconds.
	static unsigned long previousMillis;

	if( millis() - previousMillis > interval ) {
		previousMillis = millis();

		/*
			Timed code here.
		*/
	}
}

This function can be called in the main loop() function. Every time it be called, the function checks if the interval of time is reached. If so, the code within the condition is executed. The Millis() function counts the milliseconds since the Arduino is booted.

Do you hear something?

You probably saw a bit more of the project I am currently working on, the robot flower. I have completed the second prototype and it works as expected. Now, I want to give the robot the ability to interact autonomously with the environment. Not just be controlled has with the Wii Nunchuk.

I want the robot to interact with many things, but first, I wish it to detect which direction the sound come from around it. Then the flower could orient itself this way.

Sound detection technique

In think using three microphones and measure which one receive more sound will permit to know the sound direction. I saw some complex project in which they also acquire the distance by triangulation. This is too complex for what I want. The direction is enough.

Then I start digging the web for some schematics. I found many electret microphone amplifier build around an operational amplifier (Op-Amp) chip. So I check for cheap and preassembled ones on eBay. I bough different models before I get one that works as expected. Almost all the microphones breakout boards I found only detect impacted sounds, like hand clapping. I need one enough sensible to capture voice.

Electret microphone circuit boards

The advantage I found with these microphones is that it possible to connect them directly to an analog to digital converter. Then the signal can be interpreted by a microcontroller.

Testing the microphones

To find the best one for me, I first check with my DSO Nano oscilloscope what is going on at the microphone circuit output. But the real test has been to hook the microphone to my Arduino ADC input. Then with Processing, I plotted the value of the analog input on my screen. This way I really saw how they reacted to sounds and what can I get from it.

Multiplexed analog to digital converter

Then came the time I tried with two. I quickly faced the fact that the Arduino ADC reads only one input at once. It cycled to read all entries. The delay to switch from one to another take a few milliseconds. Because my idea is to get the highest microphone input at precisely the same time, using this method is useless. This delay broke all my expectation of simplicity.

After some thinking and Googling, I saw a way to use the Arduino’s ADC as a comparator.  This idea may be interesting for testing purpose, but it only works with two inputs. I continued my research and look for other microcontrollers, circuits or chips. I saw some very expensive professional devices, no microcontrollers that can do that, and finally a bunch of  ICs (AD7865) specialized for that task. However, I did not found any breakout boards for theses simultaneous-sampling ADC ICs and build one is a project by itself. So I slept on that.

Compare analog inputs

The next day I imagine another way. Not tested yet. I will need to put some parts and wires together first. My idea is to compare each input with an Op-Amp, then send the digital logic output to the Arduino.

Compare three inputs

The microcontroller will be able to understand which microphone is the highly stimulated. I think it will be possible to sample the data over a short period of time, then average the result to know which direction the sound come from. So the next step is to put all this on my proto board and test my theory!

Swash plate actuated by three servos

These lasts weeks, I work a little on the first idea that makes me renew with DIY electronics. I won’t currently tell what it is all about, I’m not ready for that now. But I want to share what giving me a headache for now. The idea is to make a plane tilt and lift, following the movement of three servo actuators. The following video of the cardboard prototype demonstrate the mechanism.

Recently I replace the mechanical part with a RC helicopter swash plate. It’s much more efficient for this prototype.

The swash plate

Servos, linkages and swash plate

The body and the servos linked to the Arduino

I tried to do the formula myself, but I’m really rusted in trigonometry. A friend’s coworker give me great help. He wrote the formula I needed to make the motor move like I imagine.

I wanted the servo motors to be actuated from a given angle of inclination, the direction of this inclination and an offset in height. There is the formula. It needs some adjustment for the offset. I still don’t really understand how to calculate it. I want the height to be relative to the ray of the swash plate.

void calculateHeights( double phi, double theta, double H, double R, double &L1, double &L2, double &L3 )
{
	const double phi1 =   0*pi/180;
	const double phi2 = 120*pi/180;
	const double phi3 = 240*pi/180;

	double x1 = R*cos(phi1);
	double y1 = R*sin(phi1);

	double x2 = R*cos(phi2);
	double y2 = R*sin(phi2);

	double x3 = R*cos(phi3);
	double y3 = R*sin(phi3);

	double nx = cos(theta)*sin(phi);
	double ny = sin(theta)*sin(phi);
	double nz = cos(phi);

	double D = nz*H;

	L1 = ( D - nx*x1 - ny*y1 ) / nz;
	L2 = ( D - nx*x2 - ny*y2 ) / nz;
	L3 = ( D - nx*x3 - ny*y3 ) / nz;
}

This is it for now. I’ll work on the function and get back with it. If you understand more than me, any help is welcome!

Buttons box for my son

There is the project I’m going to give to my two years old son this Christmas. He like playing with all kinds of buttons he found everywhere. But they almost done nothing for him, except the ones on my dryer. So I decided to give him an experience box made of many kinds of button that take different action on lights and a motor.

There are only three little electronic circuits in the box. The rest is only wiring. One circuit is a flip flop to make the two red leds flashes and the other one is an And Gate to make the two arcade button light up the yellow led only when the two button are pressed, the last one is a bicycle flash hacked to fit the panic button.

There are nothing much more to explain about this box, the pictures and the video will tell you all.

The final product

The final product

Purchased buttons and other parts

Purchased buttons and other parts

Mesuring parts

Mesure all parts

Buttons and lights placement

Buttons and lights placement

The box

The box

Drilling the holes

Drilling the holes

Prototyping the flip flip and the gate circuit

Prototyping the flip flip and the gate circuit

Building the final circuit board

Building the final circuit board

The completed circuit board

The completed circuit board

The circuit is packed in an antistatic bag. This is for isolate it from the mess of wires you will see on the next picture.

The circuit packed in an antistatic bag

The wiring inside the box

The wiring inside the box

And finally a demo

Please follow the protocol

As you have seen, the hardware part of the Glowing Marque prototype, build from an old scanner, is functioning. The last step I did is the programming of a protocol to communicate with the Arduino by the Insek Proxy Internet to Serial Proxy app.

The first issue is that I want to send a string of hexadecimal values and then convert it to real hex in the Arduino for displaying this data. The second problem to solve is to send a longer string that the serial buffer and the buffer of the Messenger library.

There is the piece of code I did for the protocol:

#include <Messenger.h>

#define DATASIZE 70
unsigned char data[DATASIZE+1]; // + 1 space for the closing \0 char.

Messenger message = Messenger();

/*
	2010-11-03: Append data.
	Args: source, target, position to start from zero to DATASIZE.
*/
void appendData(char * s, unsigned char * dp, int pos) {

	// Create and reset the pointer to display data.
	dp = dp + pos; // Move to starting position.

	char monkey[3];
	long chimp;
	for (int i=0; i<strlen(s); i=i+2) {
		monkey[0] = s[i];
		monkey[1] = s[i+1];
		monkey[2] = '\0';

		// Convert the monkey string to long int.
		chimp = strtol(monkey, NULL, 16);

		// Append chimp to displayData;
		*dp++ = (unsigned char)chimp; // Cast the long to an unsigned char.

		//Serial.print(chimp, BYTE);
	}

	*dp = '\0'; // Close the string.

}

void messageCompleted() {

	//Serial.println("Message completed.");

	while ( message.available() ) {
		//Serial.print(".");
		if ( message.checkString("data") ) { // Show text.

			if( message.checkString("flush")) {
				flushData();
				Serial.println("\nData flushed.");

			} else {
				// 1st get position
				int pos = message.readInt();

				// 2nd get length
				int length = message.readInt();

				// 3rd get data
				char tmp_data[128];

				// Move data to the temps string.
				message.copyString(tmp_data, 128);

				// Check if data length
				// Find the first position of the \0.
				int data_length = strlen(tmp_data);

				// Data are always 2 char to build one hex value.
				if( length*2 == data_length) {

						if( pos + data_length - 1 > DATASIZE) {
							Serial.println("\nData overflow.");
						} else {

						//Serial.println(strlen(tmp_data));

						//Serial.println(tmp_data);

						appendData(tmp_data, &data[0], pos);

						Serial.println("");
						Serial.println("Data:");

						for(int a=0; a < DATASIZE; a++) {
							if( data[a] == '\0' ) {
								Serial.print("-");
							} else {
								Serial.print(data[a], BYTE);
							}
						}
					}
				} else {
					Serial.println("Bad checksum.");
				}

			} // End append data.

		} else {
			message.readChar(); // Flush the rest of the message buffer.
		}

	}
}

void flushData() {
	for(int i=0; i<DATASIZE+1; i++) {
		data[i] = '\0';
	}
}

void setup() {

	Serial.begin(9600);
	message.attach(messageCompleted);

}
void loop() {
	while ( Serial.available( ) ) message.process(Serial.read( ) );
}

The protocol is relatively simple, there is the structure:

header position length data
  • The ‘header’ is the command, what the Arduino have to do with that string. I use ‘data’ as the header to send data.
  • The ‘position’ is the position in the array the data will be copied.
  • The ‘length’ is the quantity of numbers to send. It’s used to check if the Arduino received the right length of data and to verify if the data will not overflow the data array.

There is an example to send a first packet of data:

data 0 4 ff00ff00

Here I send four numbers build with two hexadecimal characters (from 00 to ff). They will be placed at the beginning of the array.

If I want to append ‘ddee33′ to this value in the array, I shall use this call:

data 4 3 ddee

So this way I can send many blocks of data and built an array longer than the serial buffer.

After that I can implement other calls to work with this data. A sample call can be (not built in this sample code): show data. I did that in code of the Glowing Marquee project, so I send packets of hex data, and ask the Arduino to show it. I will be back with more on this project in my next posts.