Thursday, 29 January 2015

Arduino MRF24J40 Wireless Shield

We will equip Arduino with wireless connectivity basing on MRF24J4 module by Microchip. As a sample application, we will remotely control a relay, operated by a floating input, and we will virtualize the Arduino USB serial port.
The MRF24J40MA radio module is manufactured by Microchip, that also provides useful and complete software libraries (identified as MiApp) for module management (creation of a complex wireless network, network identification, device addressing, sending and receiving data, etc. …). Clearly, Microchip provides those libraries free of charge only if they are compiled with MPLAB (Microchip C compiler and development environment) and executed in a Microchip CPU (PIC microcontrollers).
On other hands, Microchip provides the data-sheet of all its devices (MRF24J40MA included) and the complete knowledge base for their management. So, nothing prevents you from deeply study the data-sheet and, starting from zero, write down your own libraries for the CPU and development environment you want to use.
From these considerations, we decided to start the project that we are presenting on these pages whose ultimate goal is to use the wireless module MRF24J40MA with an Arduino hardware platform. The additional shield we developed, to have the radio module and all its components working properly, has also an output relay and an opto-coupled input. The rationale behind this choice is to equip the shield not only with the radio part but also with at least a pair of input / output so that it could be more than enough for simple applications.
Regarding our newly developed software libraries for Arduino, those cannot fully cover all of the features offered by the Microchip proprietary libraries (that allow you to create different types of networks, broadcast communications, etc ….). The operations already available are enough for the basic management of a WiFi network: module initialization, setting of network PAN ID, set the node network address, transmit and receive data. Because of these differences between Arduino and Microchip libraries, some features have been simplified. In particular, we have removed the distinction between Coordinator and End Device node but hierarchically all nodes have the same level and offer the same functionality. Maybe you lose some application optimization but surely, you have huge advantages (which, in our opinion, largely cover the disadvantages) from the point of view of simplicity and ease of use.

WiFi Hardware Chip 
MRF24J40 is a RF transceiver, compatible with 2.4GHz IEEE 802.15.4 standard.
For our applications, we will use the full version of the module (MRF24J40MA) that besides the transceiver integrates also a tuned antenna, quartz and other external components required for WiFi communication. It has a mechanical strip shape, 2,54mm step and has already passed all wireless required certifications.
To interface with an external MCU it has an SPI port, interrupt, wake and reset pins; there are also pins for power feed.
The access to the various radio functions is through the read / write of a long series of internal chip registers (for details, please consult the full product description). Our libraries shall manage these registers, hiding at Arduino application level the implementation details but offering the general function calls for configuration and communication.

Arduino MRF24J40 Library

The MRF24J40 libraries for Arduino offer some basic functions of wireless network configuration and communication. They have not all the features of Microchip MiApp but there are all the necessary functions to set up a WiFi network, to address nodes and to allow direct data exchange between them.
The library provides an object called Mrf24j for the complete WiFi stack management. The object constructor gets as input the number of Arduino pin to be used for reset, chip select and radio module interrupt (the SPI port is the default, ie pins 11, 12 and 13 for the Arduino Uno).
There is a reset function that, through the reset pin as defined above, resets the chip (best practice is to reset hardware every time the software starts) and a Init (to be called after the reset) that initializes the SPI port and the registers of the radio module.
To work properly and to exchange messages, every node needs to specify which WiFi network (PAN ID, clearly the same for all) they belong and which is its unique network address. To set the PAN ID we have to use two functions (void set_pan (word PANID) and word get_pan (void)) that respectively write and read the PAN ID chosen.

Instead to configure nodes addresses, we will use void address16_write (word address16) and word address16_read (void) (since the variable is a 16-bit word, we cannot have more than 256 nodes in the network).
Other config functions that may be useful are:

void set_channel (byte channel) that allows you to specify what radio channel to be used;
void set_promiscuous (boolean enabled) that allows you to configure whether to use normal or promiscuous rx (i.e. if you want to receive any packets from the channel);
void rx_enable(void) and void rx_disable (void) that respectively enable or disable the receiving section;
void set_palna (boolean enabled) that allows you to enable the external controller PA / LNA;
void set_bufferPHY (boolean bp), which allows to enable the receival of both user data and physical communication payload.
Let us check how the communication works and the functions involved. The first thing to say is that the whole mechanism is implemented in a special way using Arduino CPU interrupt. This implementation is perhaps a bit more difficult than usual but allows you to manage everything more efficiently involving the Arduino CPU only when necessary.
The radio chip has a pin that sends an interrupt to the CPU to indicate that it has data ready; The Arduino software must be written to handle the interrupt indicating what to do in these cases. As we shall see later by analyzing the source code, we use the Arduino attachInterrupt to indicate which function must be executed when a “change interrupt” occurs from the MRF radio interrupt pin.
The software library contains the function void interrupt_handler(void) called directly by the specified interrupt handler. The handler reads all the data from the radio module and makes it “available” again to receive further information.
Other things to define are the two functions that respectively receive and transmit data. Once you have defined these functions, the MRF24J40 library offers the methods void check_flags (void (* rx_handler) (void), void (* tx_handler) (void)) that must be called cyclically (typically in the method loop ()) to manage properly the defined handlers, avoiding overlapping between Rx and Tx.

Finally, the real functions for transmitting and receiving are respectively void send16 (word dest16, char * data) that needs parameters like network address of the destination node and the pointer to the data buffer to be transmitted and rx_info_t * get_rxinfo (void), which returns a pointer to a structure type rx_info_t specially defined to encapsulate all the information received.

Electrical Wiring



The hardware is based mainly on the WiFi module MRF24J40MA (chip U1). The radio chip needs to be managed by a main CPU through the SPI port, to receive commands and send responses. The SPI port is located on pins 5, 6, 7 and must be connected to Arduino SPI pins (SCK, MISO and MOSI).
The radio module requires a power supply of 3.3V, while the Arduino digital port works at +5V, so you cannot make a direct connection but you must match the right voltage levels. Our choice fell on an integrated circuit designed for this purpose, the chip 74HC4050D (U2 chip in the diagram). Since all the connections between Arduino and MRF24J40MA need different voltages, we will convert all of them through the 74HC4050D.
In addition to the SPI port, the radio chip also provides the Wake, Interrupt, Reset and Chip Select pins. The Wake pin is directly connected to the positive voltage level because we choose to keep always the radio on.
The Interrupt pin is connected to Arduino D2 digital port; this is because Arduino can control the pin D2 via an interrupt and, as we can see by analyzing the sketch source code, this mechanism allows a more efficient resources management.
The other two pins (Reset and Chip Select) can be operated from any other Arduino digital port; to leave a certain amount of freedom of choice (in order to be ready for further development or additional shields), we have prepared two solder bridges to each pin; by soldering one of them, you can make your own choice.
Finishing the radio module analysis, we note the 100nF capacitor C3 connected to the WiFi chip power pin (as required by the data-sheet) and the presence of a LED (green LED in the diagram) connected to the Chip Select pin of MRF24J40MA itself (in order to get the visual indication of the presence of the communication).
With regard to the communication part of the electric scheme, the analysis is done; however, we choose not to implement a simple transmission shield but equip it with at least a minimum set of input and output. In particular, we have provided a photo-coupled input (based on the photo-coupler 4N25) and an output relay (RL1 relay driven by BJT T1 stage). Also for these I / O, we decided to leave freedom of choice about which Arduino port to be used (always using the technique of the two solder bridges).
Testing
To test this sample application you need to have at least two systems MRF24J40 + Arduino Shield.
To program Arduino we use the same procedure through IDE; but first you need to modify the source code to fit the hardware pin-out chosen and change the network addresses of the two nodes. In particular, replace the variables pinResetMRF, pinCSMRF, pinShieldRele and pinShieldInput; thisNodeAddress and destNodeAddress to define source / destination nodes.
At this point you are ready to turn the system on and play with it. Try to change the status of an opto-coupler and verify that the relay of the other shots. Finally, connect with different USB cables a PC to one card; open on the PC a serial terminal (HyperTerminal or similar,”connected” to a different virtual COM port), select the configuration 9600, 8, N, 1 and no flow control and check that when “writing” the data in a window (remember that if you do not have local echo enabled you do not see what you type), these are transmitted and received on the serial port by all cards.

MP3 Player with FM Radio

This circuit is used for playing MP3 files from a memory chip, card reader or from a pen drive. Same circuit is also used for receiving telecast of FM band Radio with digital Display of frequency.
You will need MP3 Kit.
Kit include MP3 Card with Digital Display, USB port, Remote Control and connecting cables as shown in the fig below
This circuit is used for playing MP3 files from a memory chip, card reader or from a pen drive. Same circuit is also used for receiving telecast of FM band Radio with digital Display of frequency.
You will need MP3 Kit.
Kit include MP3 Card with Digital Display, USB port, Remote Control and connecting cables as shown in the fig below

Receiver
For Simplicity of the Circuit we have omitted panel button which is marked K1,K2,K3 and K4 on PCB. All function is included in remote.
Circuit Diagram of this project will be available soon.
You have to Connect an Arial for proper functioning of FM Radio. Soldering point of Arial is given on MP3 board.

Tuesday, 27 January 2015

Interface a SD Card Using

The microcontroller systems may have to back up the data which they have read during their operation or the data which they need to access during their running time. Most of the microcontrollers have built-in EEPROM memory but they come in comparatively small sizes. In order to use the microcontroller in applications like file accessing, media player etc. an external memory card is necessary. The SD memory card comes in large storage capacities ranging from 1 GB to 8 GB and they are compatible with the SPI bus of the microcontroller. The large storage capacity and simplicity in interfacing results in wide usage of SD memory card by the microcontrollers. The files in an SD memory card are stored using FAT32 or FAT16 and one should use the code or FAT file-system library to access the files from an SD card.
The easy prototyping platform Arduino provides a library for accessing the SD memory cards. This particular project explains how to interface a SD card using an Arduino board and perform some read and write operations on it.

Saturday, 24 January 2015

DC Electronic Fuse

This DC electronic fuse never needs to be replaced. It can be repaired with just a single press of the start/reset button S1. Once S1 is pressed, the thyristor T1 triggers and the current flows to the consumer load through T1 and resistor RS. Even after releasing the start button, the current continue to flow as long as the current’s value does not sink below a certain level
The current flowing through the thyristor T1 will sink below the holding level when the current is rerouted through the transistor T2 2N3055. T2 and RS are built into the electronic fuse circuit for this purpose. If the voltage drop at RS exceeds above base-emitter-diode trigger voltage of the T2, the transistor conducts thereby bypassing the thyristor. The resistance value of RS must be at least 0.2 W. It must be dimensioned that the product of RS multiplied by the fuse current value equals to 0.7 volts.
Once T2 bypasses the T1, the current flowing through the thyristor sinks below the holding level and the T1 shuts off. This in turn causes the voltage drop at resistor RS to sink below the base-emitter trigger voltage of T2 and the transistor shuts off. The end result is the shutting off of the whole circuit. The DC fuse can be reactivated by pressing the start/reset button.
The value of resistor R1 is dependent on the supply voltage. Multiply the supply voltage with 1 KW to get the value of R1. Connect the dc electronic fuse circuit to the PLUS line of the consumer load. THe coltage drop at the circuit is less than 1 volt.
DC fuse PCB layout

Wednesday, 21 January 2015

Arduino & Raspberry Pi Camera Interface

Yes,we learned that we can take mobile phone camera modules from almost all mobile phones to inteface them with our advanced hobby electronics projects just as with any other standard add-on modules. Since this calls for an appropriate microcontroller, it is better to use Arduino or Raspberry Pi microcontroller as a utile platform.
Raspberry Pi camera
Recently I’ve received a Raspberry Pi camera board. The camera, comes with a ribbon cable already attached to it,is a small size (25mm x 20mm x 9mm) board where a fixed focus 5MP camera module is attached. Part number of the camera module (from OmniVision) is OV5647. At the heart of the OV5647 camera module is a 1/4” color CMOS QSXGA (5 megapixel) image sensor with OmniBSI ™ technology. This Raspberry Pi camera module can be used to take high definition video, as well as stills photographs. It is easy to use for novices, but has plenty to offer advanced users looking to expand the knowledge.
Raspberry PI comes with two first-rate connectors on board. One is between Ethernet and HDMI, and the other is near GPIO. The one closer to Ethernet connector is Camera Serial Interface (CSI ). This CSI is directly connected to the Raspberry Pi GPU which can process images without ARM intervention 
While connecting the camera module to the CSI port (located behind the Ethernet port) of the Raspberry Pi board,ensure that camera cable is inserted in right way, ie the blue strip in the flexible cable is towards the Ethernet (LAN) port. Once you are connected,enable the camera software, test the camera and try using it with Bash or Python. As I am a newbie in the Raspberry Pi world, I haven’t drudged enough into all features and capabilities of my borrowed Raspberry Pi (and the camera module). If you want to leap into the future of amazing possibilities, have a look at the documentation
The Raspberry Pi camera board transfers data through an extremely fast camera serial interface (CSI-2) bus directly to the system-on-chip (SoC) processor. It does this through a 15-pin ribbon cable, also known as flexible flat cable (FFC), and connects to the surface mount ZIF 15 socket in the Raspberry Pi board. As you may noted, the camera module on this official Raspberry Pi camera board is identical to the camera modules (ccd imagers) found in many mobile phones
Luckily, most of the mobile phone cameras are not only MIPI compliant but also CSI compliant (see the first part of this article). The 15-pin Raspberry Pi CSI interface connector pinout is also included here to help you to keep proceed with your tinkering ideas. Note that, in Raspberry Pi, there are two flexible Flat Cable (FFC) connectors (S2 & S5). S2, near to the micro USB connector, is the Display Serial Interface (DSI). It allows low-level interfacing with LCDs and other displays with Raspberry Pi. It is a 15-pin surface mounted flexible flat connector, providing two data lanes, one clock lane, 3.3V and GND. S5, located between LAN and HDMI connector is the MIPI Camera Serial Interface 2 (CSI-2) connector for camera modules. It is a 15-pin surface mounted flat flexible connector, providing two data lines, one clock lane, bidirectional control interface compatible with I2C, 3.3V and GND. The data transmission interface in CSI is unidirectional differential serial interface with data and clock signals (the physical layer of this interface is the MIPI Alliance Standard for DPHY).
Arduino camera
Adding a camera to your Arduino UNO is not very difficult, because ArduCAM ™ Shield is infront of you. You can find a good tutorial on ArduCAM here
This tutorial will demonstrate how to use the ArduCAM shield on Arduino UNO board, aim the point and press a snapshot button you will get a BMP picture saved on the SD/TF card!
ArduCAM shield hardware integrates all the necessary components to interface with camera modules. User only need a extra support camera modules and a TF/SD card to start image capture. The ArduCAM shield includes a ArduChip which handle complex timing between MCU and LCD, Camera, FIFO. It exports a standard SPI serial interface and can be interfaced with wide range of microcontrollers. Further, ArduCAM shield includes two sets of pin out, identical in function. One is Arduino standard, it can be well mate with standard Arduino boards like UNO, MEGA2560, Leonardo and DUE etc. The other one is alternative port which can be connect to any platform like Raspberry Pi. After the great success of ArduCAM shield Rev.B, the ArduCAM team now released a more powerful ArduCAM shield Rev.C with amazing new features. This revision supports camera modules including OV7660, OV7670, OV7675, OV7725, OV2640, OV3640, OV5642 and MT9D111.
CMOS image sensor interface divided into two classes, one is DVP (Digital Video Port) interface, the other is MIPI Mobile Industry Processor Interface. The main difference between DVP and MIPI is that DVP is parallel interface and the MIPI interface is high speed differential serial interface. MIPI interface provide higher data band width than DVP interface and support higher resolution and frame rate
Image sensor is usually cheap and you can buy them for as little as $5.00 on eBay. However, when it turn into a “microcontroller-compatible camera module”, the finished board costs a lot more. In conclusion, I would have to say that it is worth spending time and effort to make your own camera modules, because the experience of reverse engineering and hacking is really interesting (at least for me). This is just a starting point, as promised I will come back with useful updates in near-future





 

XL6009 12V Universal Charger for Laptop/Notebook

I recently failed to resist buying a compact power module from eBay for almost nothing! As usual, thereafter I leaped into the inside electronics of the module, and really amazed by the hidden magic power of that little board. Yes, a simple but highly useful dc-dc boost converter block, literally, suitable for unlimited practical applications!
At the heart of this improved dc-dc boost converter is IC XL6009, which is a 400KHz 60V 4A Switching Current Boost/Buck-Boost/Inverting DC/DC Converter chip, specially design for portable electronic equipment applications. XL6009 can be configured as either a boost, flyback, SEPIC or inverting converter. The XL6009′s built in N-channel power MOSFT, fixed frequency oscillator, and the current-mode architecture results in stable operation over a wide range of input and output supply voltages. This chip, from XLSEMI, is available in TO263-5L package.


Fortunately, well-documented datasheets of XL6009 are available in the web, enough for a good insight. After the walk-through, I revert to my eBay module and drawn the schematic diagram of the module just for an evaluation. Here it is


 
According to XL6009 IC datasheet, this module’s output voltage can be calculated using the formula Vout = 1.25x(1+R/1K), where R is the value of the potmeter. Any idea spark? Yes, now it is very easy to output a high-current DC supply voltage near 19VDC, from an input supply voltage of 12 VDC!
The findings shed some light on the fact that, with the help of this module, it’s very easy to build a Universal Laptop/Notebook Charger for in-car applications. As an aftereffect, I build a compact Universal Laptop/Notebook Charger wired around the XL6009 module as shown in the next circuit diagram.
This charger receives 12VDC supply input from the car battery through the in-dash cigar lighter socket, and gives powerful DC voltage output for energizing the connected laptop/notebook computer. Built-in 0-30V digital voltmeter module (DVM) – another fancy item from eBay – simplifies the output voltage setting task.
Remember to set the output voltage to a default value of 19VDC using the 100K (incircuit value of 50K) potmeter. Finally, attach your own standard/custom laptop/notebook power cable with proper connector (dc power jack) at the output of the universal charger.
Test Result:
  • Input Voltage: DC12V/5A (from lab power supply)
  • Output Voltage: DC 19V (pre-setted)
  • Output Current: 1.5 A (typical)
  • Input Voltage: DC12V/5A (from lab power supply)
  • Output Voltage: DC 15V (pre-setted)
  • Output Current: 2.0 A (typical)


Arduino 8×8 LED Matrix

8×8 LED Matrix modules are now widely available, and fortunately they are easy to use with our favorite Arduino microcontroller. 8×8 LED Matrix module have many applications in real life, such as various types of electronic display panels.
The LED matrix can be driven in two ways (parallel or serial). Here we drive it in the serial manner in order to save interface (needs only three data lines). The serial-driven LED matrix actually dynamically displays the LEDs (row-by-row or column-by-column). The persistence of vision for humans is about 0.1s, so as long as we can serially display all 8 rows/columns within 0.1s, we’ll see a complete character or pattern.
Our project is infact an Arduino with Serially Interfaced MAX7219 Operates an 8X8 LED Matrix to display a heart pattern. The MAX7219 IC is a serial input/output common-cathode display driver that interfaces microprocessors to a 7-segment numeric LED displays of up to 8 digits, bar-graph displays, or 64 individual LEDs. For convenience, here an 8×8 LED matrix, integrated with a MAX7219 IC setup, available as a pre-wired module is used. Typical specification of this LED Matrix Module is shown below:
  • Operating Voltage: DC 4.7V – 5.3V
  • Typical Voltage: 5V
  • Operating Current: 320mA
  • Max Operating Current: 2A 

 
Wiring Instructions
  1. Connect Arduino pin8 to DIN on 8×8 LED Matrix
  2. Connect Arduino pin9 to CS of 8×8 LED Matrix
  3. Connect Arduino pin10 to CLK of 8×8 LED Matrix
  4. Connect an external 5VDC (1A) to VCC of 8×8 LED Matrix
  5. Connect external 5VDC supply’s GND, to the GND of 8×8 LED Matrix Module
Note that the 8x8LED Matrix Module should be common-grounded with Arduino, ie, always remember to interconnect the Arduino GND terminal with the external 5VDC power supply GND terminal. Connect pins according to the instructions given above, and download the sketch into Arduino board. If everything seems right, you can power up the Arduino (and the LED matrix) to see the LED matrix circularly displays a ‘sweetheart’ pattern!
Wiring Diagram
Warning!
Before powering up, ensure that corresponding wires are properly connected.