Sunday, October 25, 2015
Tuesday, October 20, 2015
Programming ESP8266-ESP07 modules
![]() |
| ESP8266-ESP07 module on the breadboard |
(1) Download and install Arduino 1.6.5 version (go to build directory and type 'ant run').
(2) Start the Arduino IDE and then open the preferences menu. There's a text field for Additional Board Manager. Enter the following string in this field.
(3) Now open the Board Manager from Tools->Board menu, search for esp8266 platform and install it.
(4) Now, go to the Tools->Board menu and select "Generic ESP8266 Module". Settings related to this board from the Tools menu should be configured as follows.
Flash Frequency: 40MHz
CPU Frequency: 80MHz
Upload Using: Serial
Upload Speed: 115200
Flash Mode: QIO
Flash Size: 1M (512K SPIFFS)
Now our Arduino IDE is ready.
(5) Connect the ESP8266-ESP07 module with the USB-FDTI module as shown below.
| ESP8266-ESP07 | FDTI programmer |
|---|---|
| Tx | Rx |
| Rx | Tx |
| GND | GND |
| GPIO15 | GND |
| GPIO0 | GND |
| VCC | 5V * |
| CH_PD (EN) | 5V * |
* = connect two diodes to drop the voltage to 3.3v
(6) Connect the USB-FDTI module to a USB port of the PC where we run the Arduino IDE. From File menu go to Examples->ESP8266WiFi->WiFiAccessPoint sketch. Change the access point name given in the code to whatever we want.
Now, we can directory program it to the ESP8266 module but before clicking the Upload button of the Arduino IDE, disconnect the VCC supply from the module and connect again. Then only we can program it. Otherwise, it will throw an error. While the code is uploading, blue LED of the ESP8266 module will blink.
(7) After the code is completed uploading, remove the GPIO0 pin from the GND connection. Then disconnect and reconnect the VCC of ESP8266-ESP07 from the FDTI VCC supply. Now, we can check whether the access point is up and running.
Open a Linux terminal and issue the following command which will list the ESSIDs of the access points in the vicinity together with their signal strengths.
sudo iwlist wlan0 scanning | grep -e "ESSID:" -e "Signal level"
In this list, we should be able to see our new access point created by the ESP8266 module.
(8) If we get connected to this access point using the correct password, then we can open a web browser and enter the IP address http://192.168.4.1/ in the address bar. It should return a HTTP response saying "You are connected".
References:
Sunday, September 20, 2015
Debugging Digital Circuits with a Logic Analyzer
While working with digital systems of various kinds, sometimes we face unexpected behaviors from those tiny embedded platforms. Sometimes it can be a hardware defect and sometimes it's just a bug in our code that runs on those systems. Unlike other platforms such as personal computers and smartphones, debugging these embedded systems is very hard and complicated. In this domain, one important tool that helps the developers to look in to the lower level functionalities of a digital circuit is a logic analyzer.
In our lab, we had a very nice logic analyzer tool donated to us by a past colleague who worked here. The tool is Logic manufactured by Saleae. Today I put my hands on it and tried some simple things to get familiarized with the device. First I programmed an Arduino Uno board to blink its on-board LED connected to the pin 13. Then I connected the Logic to the Arduino board. Ground pin of Logic was connected to a Ground pin of Arduino board. Then, pin 1 of the Logic is connected to the Arduino pin 13 using a jumper wire.
Go over to the download page of the Saleae website and download the required software. In my case, I downloaded version 1.1.15 for Ubuntu 12.04. Simply uncompress the ZIP file and there we have an executable file. I ran it from a terminal by issuing the command sudo ./Logic and the software started up. Connect the Logic device to to the computer using the USB cable and then simply clicking on the Start button will capture the data. Having a 1000 millisecond delay between the turning on and off of the LED, I was able to see the output from the software interface as shown below.
Timing seems very precise. Once the pin 13 became high, it took about 1000.872 milliseconds before it switch back to low. In our program code, the delay was set as 1000 milliseconds. As the second test, I removed the delays placed in the code, That means our LED is turning on and off as faster as the AVR microcontroller can perform. Our logic analyzer says that pin 13 stays about 4 microseconds in high state before it return to low.
I think this device will help me in my future endeavors with digital circuits. Let's see what it will bring to me.
Reference:
[1] https://www.saleae.com/
[2] https://www.youtube.com/watch?v=7OCPWCdg2ys
Go over to the download page of the Saleae website and download the required software. In my case, I downloaded version 1.1.15 for Ubuntu 12.04. Simply uncompress the ZIP file and there we have an executable file. I ran it from a terminal by issuing the command sudo ./Logic and the software started up. Connect the Logic device to to the computer using the USB cable and then simply clicking on the Start button will capture the data. Having a 1000 millisecond delay between the turning on and off of the LED, I was able to see the output from the software interface as shown below.
![]() |
| Arduino Uno pin 13 switching with 1000 ms delays |
Timing seems very precise. Once the pin 13 became high, it took about 1000.872 milliseconds before it switch back to low. In our program code, the delay was set as 1000 milliseconds. As the second test, I removed the delays placed in the code, That means our LED is turning on and off as faster as the AVR microcontroller can perform. Our logic analyzer says that pin 13 stays about 4 microseconds in high state before it return to low.
![]() |
| Arduino Uno pin 13 switching without explicitly placed delays |
I think this device will help me in my future endeavors with digital circuits. Let's see what it will bring to me.
Reference:
[1] https://www.saleae.com/
[2] https://www.youtube.com/watch?v=7OCPWCdg2ys
Monday, September 7, 2015
FM Radio Broadcasting with HackRF and GNURadio
Here's a flow graph which can be used for broadcasting some content of a Wav file over FM radio frequencies. The original flow graph is from here but it created a lot of missing block errors. So I had to edit it a little bit to make something my own which can be downloaded from here. Since it requires a Wav file, I generated it from a MP3 song file using a tool called Sox as follows.
sudo apt-get install sox
sudo apt-get install libsox-fmt-mp3
sox phillip-phillips-home.mp3 -b 16 phillip-phillips-home.wav
Here's how the flow graph looks in GNURadio Companion tool.
GQRX for Quick SDR Jobs
While GNURadio provides very sophisticated capabilities to implement transmitters and receivers using SDR hardware platforms, it is not necessary to create flow graphs and run them in order to view the radio spectrum. For any quick and dirty requirement to view the spectrum, the easiest way is to use GQRX, which is a receiver program based on GNURadio.
Here's some screenshots of GQRX tuned to various frequencies.
Jamming WiFi Channels with HackRF
We can easily capture signals going in a particular frequency using HackRF and also we can retransmit those data back to the air from the file. Here's how we use it to jam some wifi channels. To try this, first I checked what is the specific frequency channel, which is used by my laptop and the WiFi hotspot to communicated. We can find it out by using the following command.
iwlist wlan0 channel
It should list down all the available WiFi channels and at the end, the channel currently we are using. In my case, it was channel 11 which operated in 2.462 GHz. Now it's time to try jamming. First we should record some data to a file. We can do it with the following command. The parameter -f specify the frequency we need to tune in to in Hz. Similarly the parameter -s specify the sampling rate which I have set to 20 MHz. Finally the parameter -l specify the LNA gain. Reading man files will provide more information about those stuff.
hackrf_transfer -r test.bin -f 2462000000 -s 20000000 -l 40
This command will run for a while and save data to the file test.bin and stop at some point. Still, the reason to stop in that way is mysterious to me. Anyway, now we have some captured data. We can transmit it back. Before doing so, open a new terminal and ping to some public IP address such as 8.8.8.8 so that we can continuously see the ICMP packets going and coming with round trip information. While having the ping command running in that terminal, run the following command from our original terminal. That -x parameter sets the Tx VGA gain.
hackrf_transfer -t test.bin -f 2462000000 -s 20000000 -x 47
During the time period of above transmission going on, we can see that the ping packets are getting disturbed. Either they take a longer round trip delay or completely become unable to be delivered.
Here's a reference I used,
Saturday, August 29, 2015
Processing data out of GNURadio
While working on software defined radio (SDR), I have always worked on GNURadio software which provide a graphical interface. I have to drag and drop various blocks to create flow graphs which perform the functionality I need. It's time to escape the barriers of GNURadio and do further thing out of it. Finally I found the way to do it. We can start with GNURadio flow graphs and transfer data from it to our own python scripts where we have the freedom to do whatever we want with our program codes. I found some good resources from where I learnt it and those things are mentioned under the references section.
First of all to try these things, we need to have installed some software. GNURadio should be there as obvious. Additionally we need a python plotting library which we will be using. Install it as follows.
Let's clearly understand what we are going to do now. When we run a flow graph created using GNURadio, it will acquire the data from wherever we specified and will process it inside. Resulting data can be visualized as different plots provided as blocks within the flow graph or sometimes we can save data in to a file. Every kind of processing I have done so far are within the flow graph. Now, what we are going to achieve is creating a flow graph which has some special blocks. Instead of running the flow graph straightforwardly, we just generate a python script using GNURadio that represent the flow graph. Then we write a our own python program which will use that GNURadio generated python script as a module to acquire data and then do further processing of data inside our own python script.
It's time for action. Open gnuradio-companion tool and create the following flow graph. It will acquire data from a HackRF device and apply a fast fourier transform (FFT) operation on the data stream. Finally it turns that FFT data in to message block which are ready to be sent out of the flow graph though a special block. I saved this flow graph as fft_data.grc and clicked on the 'generate flow graph' button to generate the python script which implements this flow graph is code. It generates the script called top_block.py automatically.
Once this is done, we have a python script which will acquire data and provide us FFT data. Let's use it in a our own python script. For this purpose, create a new python program with the name fft_plotter.py and add the content shown below. It should be understandable that we have two functions there. First one draws the FFT for the considered frequencies while the second one draws the variation of signal power of a particular frequency over time. Depending on what we want to plot, we can uncomment the relevant line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | import grcconvert import struct grcconvert.main("top_block.py") import top_block import matplotlib.pyplot as plot import os from collections import deque def plot_fft(with_this): #Asanka: trying to play with this os.system('clear') print "------------------------------" print "length =", len(with_this) print "start point =", with_this[0][0], "dB" print "center point =", with_this[len(with_this)/2][0], "dB" print "end point =", with_this[len(with_this)-1][0], "dB" print "------------------------------" plot.clf() # it seems logpwrfft exchanges the first and second part of the FFT output, we correct it: plot.plot(with_this[len(with_this)/2:]+with_this[:len(with_this)/2]) plot.draw() def plot_power(data_array): os.system('clear') print '\n\n' print "signal strengh at the center:", data_array[len(data_array)/2][0],"dB" a1.appendleft(data_array[len(data_array)/2][0]) datatoplot = a1.pop() line.set_ydata(a1) plot.draw() plot.pause(0.00001) plot.ion() tb=top_block.top_block() tb.start() #Asanka: experiment a1 = deque([0]*100) ax = plot.axes(xlim=(0, 100), ylim=(-100, 0)) ax.grid(True) line, = plot.plot(a1) plot.ylim([-150,0]) plot.show() while True: fft=tb.msgq_out.delete_head().to_string() # this indeed blocks floats=[] for i in range(0,len(fft),4): floats.append(struct.unpack_from('f',fft[i:i+4])) print "got",len(floats), "floats; FFT size is", tb.fft_size i=0 while i<len(floats): # gnuradio might sometimes send multiple vectors at once pack=floats[i:i+tb.fft_size-1] #plot_fft(pack) plot_power(pack) i+=tb.fft_size |
This python script and the gnuradio-companion generated python script should be there in the same directory. Finally we need one more python script before we can try running this code. It can be obtained from here and saved into the same directory. It's written by Andras Retzler and I got the code from an example he provided in github.
Now I think we are good to go. Connect HackRF device into a USB port of the computer and run our python script with root privileges.
sudo python fft_plotter.py
Depending on the function we call within our script (we cannot call both at the same time), we will be able to see two different plots as follows.
sudo python fft_plotter.py
Depending on the function we call within our script (we cannot call both at the same time), we will be able to see two different plots as follows.
References:
Subscribe to:
Posts (Atom)











