Monday, September 23, 2013

Basic setup of OpenWRT on DIR-601 B1 with cable modem


How to install OpenWRT on DIR 601 B1 router and set up a basic network

Internet service provider: TWC
Modem: DOCSIS 2.0 (no wireless)
Router connected to modem.

Note:
It appears that LuCI cannot be installed on this router because there is not enough space available on the device, although it might work if you build own firmware image.

All of the following information is readily available on other websites. I just combined and posted it here for convenience.
  1. Download the latest OpenWRT image:     http://downloads.openwrt.org/snapshots/trunk/ar71xx/openwrt-ar71xx-generic-dir-601-b1-squashfs-factory.bin
  2. Flash according to these instructions: http://wiki.openwrt.org/toh/d-link/dir-600
    Briefly, set PC IP address to 192.168.0.2, press reset button, power up router, use web UI at 192.168.0.1 to upload new image
  3. Login using putty via telnet protocol to 192.168.1.1
  4. Use passwd to change password
  5. Login using putty via ssh protocol
  6. Edit /etc/config/wireless via CLI:
    1. Change ssid (network name) from "OpenWRT" to your network name:
      
      uci set wireless.@wifi-iface[0].ssid="NetworkName"
      
    2. Change "encryption" to "psk2"
      
      uci set wireless.@wifi-iface[0].encryption="psk2"
      
    3. Change "key" to "yourpassword"
      
      uci set wireless.@wifi-iface[0].key="yourpassword"
      
  7. Enable wifi, commit changes, restart wireless interface:
    
    uci set wireless.@wifi-device[0].disabled=0; uci commit wireless; wifi
    
  8. Plug in router to modem, power cycle cable modem
If you have DSL, you would also need to install pppoe packages and include your username and password to the config files.

Monday, June 10, 2013

JY-MCU BT board V1.05 configuration with Arduino

Configuring the cheap bluetooth module from ebay is more difficult than appears at first, especially since datasheets provide conflicting instructions for programming the chip. I found useful another blog post, although they do not provide explicit Arduino code for configuring the bluetooth module.

Wiring
Arduino Mega 2560 JY-MCU
TX1 (18) RXD
RX1 (19) TXD
+5V VCC
GND GND
By default, the module uses 9600 baud rate. The task is to configure it for 115200 bps using the AT command set. If this is the first time module is being configured, change "Serial1.begin(115200);" to "Serial1.begin(9600);".

Code for Arduino

int led = 13;
/* used help from http://byron76.blogspot.com/2011/09/one-board-several-firmwares.html */
void setup() { 
 pinMode(led, OUTPUT);
 Serial.begin(115200);
 Serial1.begin(115200);//use 9600 if first set up
}
void loop() {
 digitalWrite(led, HIGH);//sanity check
 command("AT",2);// response: OK
 command("AT+VERSION",12);// response: OKlinvorV1.5
 command("AT+NAMEArduino",9);//response: OKsetname
 command("AT+BAUD8",8);//response: OK115200
 while(1);//stop execution
}
void command(const char* cmd, int num_bytes_response) {
 delay(1000);
 Serial1.print(cmd);
 delay(1500);
 for (int i=0;i<num_bytes_response;i++)
 Serial.write(Serial1.read());
}

Edit 2013-08-21: Fixed a typo in the code (character "<" not displayed properly)

Compile and upload the above program to the Arduino.  Open the serial monitor (at 115200 baud rate) to check whether the module responds properly. Do not pair to the bluetooth module until after configuration is complete. Without the delay commands, it appears that the bluetooth chip cannot keep up. This code can be easily expanded to send other commands to the module as well. 

Monday, February 11, 2013

Cottage cheese pancakes

This recipe is based on the original post in allrecipes.com and modified according to reader comments and ingredient substitutions.

What you need:

IngredientQuantity
Flour   13 cup, a bit more is ok
Sugar   14 cup
Cottage cheese           1 cup
Eggs   3
Baking soda   slightly less than 14 teaspoon
Vanilla extract   12 teaspoon
Vegetable oil   2 tablespoon
Lemon juice   34 teaspoon

Instructions:

  1. Combine all ingredients except for lemon juice in the order listed. The order has been optimized for utensil reuse.
  2. Stir the ingredients with a fork, trying to break the cottage cheese clumps. I use small curd cottage cheese from Ralphs.
  3. Add lemon juice, and stir again.
  4. Bake on a frying pan greased with vegetable oil on 4.256 setting.


Saturday, January 12, 2013

Low pass filter solution

Problem: periodic noise in data (see blue curve below).
Sampling frequency: 40 Hz
Expected signal frequency: 10 Hz

Solution: low-pass filter (Butterworth)
Matlab already provides the framework for filter design (Butterworth filter in Matlab).
For explicit algorithms see http://www-users.cs.york.ac.uk/~fisher/mkfilter/
(specifically http://www-users.cs.york.ac.uk/~fisher/mkfilter/trad.html)
Explanation for how filters work: http://www.electronics-tutorials.ws/filter/filter_8.html
Matlab filter usage: http://faculty.smu.edu/hgray/software/matlabfilterinstructions.pdf
Briefly:
  • the higher the order, the sharper the cutoff (see link above, 'how filters work')
  • Nyquist frequency is equal to half of sampling frequency
  • cannot apply filter to frequencies above Nyquist
Matlab code:
Input is a 1D array of current measurements labeled "f". Output is array "filt".
 f = f.*1E9; %convert to nA  
 time=(1:length(f)).*(1.0/40); % 40 Hz sampling rate  
 datahandle=plot(time,f);  
 xlabel('Time, s');  
 ylabel('Current, nA');  
 hold on;  
 sampling = 40; % sampling frequency = 40 Hz  
 nyquist = sampling/2; % nyquist frequency is half of the sampling frequency  
 cutoff = 15; % cutoff frequency = 15 Hz  
 n = 3; %filter order (higher is sharper cutoff)  
 Wn = cutoff/nyquist; % normalized cutoff frequency  
 [b,a]=butter(n,Wn); % get Butterworth coefficients  
 filt=filter(b,a,f); % apply filter to data  
 plot(time,filt,'Color','Red');  
 legend('Raw','Filtered');  


Results:
1) No signal present. Expect a flat line in raw data.
Clearly measurement has periodic noise. Filter removes the noise very well. Note the ripple in the the beginning of the filtered data.
Zoom:

2) Signal is present around t = 1s.

The spike in the beginning is an artifact of the algorithm. A quick solution is to insert fake data (repeated first value of the input array) in the beginning of the input array, apply the filter, and then remove the same amount of data from the beginning of the filtered array.
Matlab code:
 f = f.*1E9; %convert to nA
time=(1:length(f)).*(1.0/40); % 40 Hz sampling rate
datahandle=plot(time,f,'Linewidth',2);
xlabel('Time, s');
ylabel('Current, nA');
hold on;
sampling = 40; % sampling frequency = 40 Hz
nyquist = sampling/2; % nyquist frequency is half of the sampling frequency
cutoff = 15; % cutoff frequency = 15 Hz
n = 3; %filter order (higher is sharper cutoff)
Wn = cutoff/nyquist; % normalized cutoff frequency
[b,a]=butter(n,Wn); % get Butterworth coefficients
pad_length = round(length(f)*0.1); % 10% of original data length
f = [ones(pad_length,1).*f(1); f]; %insert fake data in the beginning of the array
filt=filter(b,a,f); % apply filter to data
filt=filt(pad_length+1:length(filt)); %remove the fake data
plot(time,filt,'Color','Red','Linewidth',2);
legend('Raw','Filtered'); 


Results:
1) No signal present. The spike in the beginning is reduced.
2) Signal present around t = 1s. 



2000 Pontiac firebird front turn signal light bulb replacement

Vehicle: 2000 Pontiac Firebird Formula
Symptoms: when signaling a turn, the blinker inside the car on the dashboard does not blink, but remains solid all the time.
Problem: the turn signal light bulb is out
Light bulb part: 3157NA (amber color). Light bulb reference: http://ls1tech.com/forums/appearance-detailing/1398916-official-4th-gen-f-body-light-bulb-list.html
Procedure:
1. Unscrew two bolts on the bottom of the car on the side where you're trying to replace the light bulb. The socket is a metric 10 I believe. Then plastic flap will be able to swing freely.
2. Insert your hand in the opening and twist the light bulb (with wires) from the housing. The wire is long enough to extend light bulb to the opening.
3. Remove light bulb.
Reverse the procedure to install the light bulb. No need to get under the vehicle for this repair.

O'Reilly Auto Parts did not have LED versions of the bulb, only regular.
The cost was around $6 for a pair of light bulbs.