Saturday, November 16, 2013

BE MAKER, desde Cero hasta el Internet de las Cosas[Español]

Si eres nuevo en el mundillo de la electrónica y quieres empezar creando proyectos con Arduino, deberías empezar por un Starter Kit. La mayoría de ellos suelen ser caros y cuando finalizas tu aprendizaje sus componentes no son muy útiles en su mayoría.  Borderless Electronics acaba de desarrollar un nuevo Starter Kit llamado  BE MAKER.

BE BOARD
BE MAKER incluye 600 componentes distintos por solo 29$. Ademas incluye una guía completa, con vídeos, para aprender desde cero hasta el Internet de las cosas.Para completar el kit necesitaras una Arduino Leonardo, aunque también puedes comprar la BE BOARD, una Arduino Leonardo que solo cuesta 9$.

En mi opinión, deberías adquirir la BE SHIELD también. Esta shield permite seguir los tutoriales de forma más sencilla, usando menos cables.Ademas, la shield es muy útiles para proyectos futuros porque incluye un puerto  Ethernet y un zócalo para tarjetas microSD. La shield cuesta 15$, aunque si la compras con el pack te costara solo 10$. En el futuro subiré proyectos más avanzados usando la BE SHIELD porque permite realizar proyectos alucinantes sin mucho coste.  

BE SHIELD
Puesdes comprarlo y coloborar con el proyecto aquì http://igg.me/at/bemaker/x/5411932
Si quieres seguir tutoriales más complejos deberías primero aprender a usar el entorno arduino con este kit. En el caso de que sea un usuario más avanzado es una buena oportunidad para comprar un hardware extra a muy buen precio.

Friday, November 15, 2013

BE MAKER, from Zero to Internet of Things

If you are new on electronics and you want to start working with arduino, you should start with a starter Kit. Most kit's are quite expensive and then when you finish your lessons the kit become unuseful. Recently, Borderless Electronics had developed a new starter kit. This kit is called BE MAKER.

BE BOARD
BE MAKER includes 600 different's parts for only 29$. It also  includes a complete guide to learn from zero to Internet of Things, using videos. With the kit you would need an Arduino Leonardo or just buy the BE BOARD. The BE BOARD  works as an Arduino Leonardo but the board only cost 9$

In my opinion, you should buy the BE SHIELD too. The shield permits to use the kit's without using a lot of wires. Furthermore, the shield is very useful for future projects, because includes an Ethernet port and a SD Card holder. The shield costs about 15$,but  with some packages it only costs10$. I will update some tutorials using this shield because it will  allow me to prepare some coll stuff.

BE SHIELD
You can buy it and collaborate with the project here http://igg.me/at/bemaker/x/5411932
If you want to  go trough the advanced tutorials you should learn with this kit first. Also, If you are an advanced user, the kit is a big deal if you want
to have extra hardware.

Sunday, October 20, 2013

Tutorial: Battery charge indicator

If you have your own robot, you will see that you run out of battery at the worst moment. You can prevent this problem using a  Battery charge indicator. You only have to build an easy circuit that uses the integrated circuit LM339N. With this integrated circuit  you will have a Battery charge indicator with five different's levels of charge. Also, in this tutorial we will see how to prepare this circuit to connect it  on an Arduino.

This circuit is calculated for 7.2 volts batteries. That means that ONLY works with 7,2 volts. If you need a Battery charge indicator  for other batteries, you have to change the resistors. I can upload a post, if you ask for them on the comments.

Materials

  • LM339N
  • L7805CV
  • Variable Resistor 2KOhms
  • 3 X 220 Ohms Resistor
  • 8.2 KOhms Resistor
  • 4.7 KOhms Resistor
  • 4 leds (with diferent color will look better)

The circuit

Here is a diagram with all the connections that we had to made. I recommend to test it on a protoboard before make any soldering.

Setting up

Before using it we have to calibrate the Battery charge indicator. To calibrate we have to connect a full charge battery and move the variable resistor until all the led's are switched on. Then you have a practical Battery charge indicator! If you have  four led's on your battery is full charge and when all led's are off you have to change the batteries. 

Soldering and preparing for Arduino

Two circuits in the same board
In my case I have two independents  circuits on the same PCB. I also added a switch that permits to use the circuits with out powering the leds. Instead of that, you can connect four wires ( one per each led) to the arduino and print the battery status wherever you want. It just work like a switch, you can get 0 (led off) or 1 (led on).

Please leave a comment an subscribe for new tutorials. You can send your ideas or projects to controlrobotics@rodrigomompo.com

Tuesday, October 8, 2013

Sending floats using VirtualWire

We have a problem when we want to send floats using Virtual Wire.If you read the previous tutorials, and you tryed to send floats, you probably got ? .Arduino haven`t got enought power for using all functions with floats. Some functions like sscanf or sprintf are implanted but with out all the functions. You can send strings, ints but not floats because the hardware isn't enought powerfull to suport this part of the function.

 What can we  do?

Well, insted of sending floats we can convert the data into an string, send it and then, in the receiver, convert into a float again . This will be very easy using this function

dtostrf (double __val, signed char __width, unsigned char __prec, char *__s);

For more information: http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga060c998e77fb5fc0d3168b3ce8771d42

In the receiver when we get the string we have to use the following lines of code:

char floatbuf[32]; // make this at least big enough for the whole string
stringwithfloat.toCharArray(floatbuf, sizeof(floatbuf));
float f = atof(floatbuf);

Thursday, September 19, 2013

Tutorial: Arduino + Kit rf 433Mhz (Part4: Multiple variables)

In the final part of this tutorial we will see how to send multiple variables using virtual wire. Let's start then.

There are a lot of forms to send multiple variables trough virtual wire. However,if we want to send different types of data or just send some int's, we can do in the same way, with this code.

Transmitter

With Virtual Wire we can only send an string. So if we want to send other types of data, we need to convert this data into a string.

Fortunately, there are a function to do this. Here is the following  line of code that we have to add.

// Function sprintf
 sprintf(Stringtosend, "%d,%d,%d,%d,", Variable1, Variable2, Variable3, Variable4);
The funcion sprintf converts differents types of data into a string. The función works like this:
sprintf(Stringtosend, specifier of the type of data, data);

specifierOutputExample
d or iSigned decimal integer392
uUnsigned decimal integer7235
oUnsigned octal610
xUnsigned hexadecimal integer7fa
XUnsigned hexadecimal integer (uppercase)7FA
fDecimal floating point, lowercase392.65
FDecimal floating point, uppercase392.65
eScientific notation (mantissa/exponent), lowercase3.9265e+2
EScientific notation (mantissa/exponent), uppercase3.9265E+2
gUse the shortest representation: %e or %f392.65
GUse the shortest representation: %E or %F392.65
aHexadecimal floating point, lowercase-0xc.90fep-2
AHexadecimal floating point, uppercase-0XC.90FEP-2
cCharactera
sString of characterssample
pPointer addressb8000000
nNothing printed.
The corresponding argument must be a pointer to a signed int.
The number of characters written so far is stored in the pointed location.
%% followed by another % character will write a single % to the stream.%

In the table we see the different specifiers  for all the types of data. Using this funcion we can also send an integer and a floating point

sprintf(Stringtosend, "%d,%f,", integer, floatingpoint);

For more information you can see the C++ reference http://www.cplusplus.com/reference/cstdio/printf/

Transmitter Example 


/*.............................................................
Sending Multiple Variables Using VirtualWire. Transmitter
Author: Rodrigo Mompo Redoli
For controlrobotics.rodrigomompo.com
..............................................................*/
#include <VirtualWire.h>

int Sensor1Pin = A1;// The pins were sensor are attached
int Sensor2Pin = A2;
int Sensor3Pin = A3;
int Sensor4Pin = A4; 
int ledPin = 13;
int Sensor1Data;// The variable were the data from each sensor
int Sensor2Data;// will be stored 
int Sensor3Data;
int Sensor4Data;
char Sensor1CharMsg[21];// The string that we are going to send trought rf 

void setup() {

 // LED 
 pinMode(ledPin,OUTPUT);
 
 // Sensor(s)
 pinMode(Sensor1Pin,INPUT);
 pinMode(Sensor2Pin,INPUT);
 pinMode(Sensor3Pin,INPUT);
 pinMode(Sensor4Pin,INPUT);
 
 // VirtualWire setup
 vw_setup(2000); // Bits per sec
 vw_set_tx_pin(12);// Set the Tx pin. Default is 12

}

void loop() {
  
  // Read and store Sensor Data
  Sensor1Data = analogRead(Sensor1Pin);
  Sensor2Data = analogRead(Sensor2Pin);
  Sensor3Data = analogRead(Sensor3Pin);
  Sensor4Data = analogRead(Sensor4Pin);
  
  sprintf(Sensor1CharMsg, "%d,%d,%d,%d,", Sensor1Data, Sensor2Data, Sensor3Data, Sensor4Data);
 
 // Turn on a light to show transmitting
 vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg));
 vw_wait_tx(); // Wait until the whole message is gone
 // Turn off a light after transmission
 delay(40);

}

Receiver

Now we must be able to send an string and receive it. However ,with this string you can't do anything unless you discompose it and storage on differents variables.For this new challenge we are going to use another function.

 sscanf(StringReceived, "%d,%d,%d,%d",&Sensor1Data, &Sensor2Data,&SeensorData3,&SensorData4);

This function is the opposite of sprinft, and let´s you to storage the information on differents variables. Compile the  receiver code and add some cool things that use this data.

At the end of the code you should erase all the previous data from the string where the new string is storage, so you must call this function

 memset( StringReceived, 0, sizeof( StringReceived));// This line is for reset the StringReceived

Receiver Example

/*.............................................................
Sending Multiple Variables Using VirtualWire. Receiver
Author: Rodrigo Mompo Redoli
For controlrobotics.rodrigomompo.com
..............................................................*/
#include <VirtualWire.h>
 
// Sensors 
int Sensor1Data;
int Sensor2Data;
int SensorData3;
int SensorData4;
 
char StringReceived[22]; 
 
 
 
void setup() {
    // VirtualWire 
    // Initialise the IO and ISR
    // Required for DR3100
 
    // Bits per sec
    vw_setup(2000);
    vw_set_rx_pin(11);  
     
    // Start the receiver PLL running
    vw_rx_start();       
 
} // END void setup
 
void loop(){
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
     
//Taking the data from the control base
    if (vw_get_message(buf, &buflen)) 
    {
 int i;
        // Message with a good checksum received, dump it. 
        for (i = 0; i < buflen; i++)
 {            
          // Fill Sensor1CharMsg Char array with corresponding 
          // chars from buffer.   
          StringReceived[i] = char(buf[i]);
 }
 
      sscanf(StringReceived, "%d,%d,%d,%d,%d,%d",&Sensor1Data, &Sensor2Data,&SensorData3,&SensorData4); // Converts a string to an array
         
        // Turn off light to and await next message 
        
    }
 
 memset( StringReceived, 0, sizeof( StringReceived));// This line is for reset the StringReceived
}
Please leave some comments, and send your ideas for new posts in this blog. Also, If you have a project you can publish it on my blog. Subscribe and add me to your Google plus circles.

Saturday, August 24, 2013

Tutorial: Arduino + Kit rf 433Mhz(Part3: Software)

 If you are reading this post, you have a Rf link kit working with the example code of Virtualwire. If not you should read part 2  of this tutorial. Today we are going to go through Virtualwire understanding all the functions of this library.

Virtualwire Library

Virtualwire is a library made by Mike McCauley. The library is distributed under an Open Source License. You can use it even if you are making money but you have to distribute your code with Open Source License. However, it's time to view all the functions of the library.

Transmitter 

For the transmitter we have the following functions:
  • vw_set_tx_pin(pin); This function just sets the transmitter pin. The default pin is 12.
  • vw_setup(uint16_t speed); is used to set the speed of the communication.
  • vw_wait_tx(); is very usefull, you call it after sending the message and the arduino will wait until all the message has gone. Then the program would continue.
  • vw_send((uint8_t*) message, message len);  This function is used to send the message. To understand how it works we will decompose it. The function is vw_send(); inside it you have to put the message.So, you have to put (message, message len). It's very simple. Also, you have this part  (uint8_t*), you have to write it before the message, it's like the function (byte*). 
Note: The function strlen(), is used to obtain the size of the string, the easiest way of doing that.

// transmitter.pde
//
// Simple example of how to use VirtualWire to transmit messages
// Implements a simplex (one-way) transmitter with an TX-C1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley
// $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $

#include <VirtualWire.h>

void setup()
{
    Serial.begin(9600);   // Debugging only
    Serial.println("setup");

    // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);  // Bits per sec
}

void loop()
{
    const char *msg = "hello";

    digitalWrite(13, true); // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(13, false);
    delay(200);
}
Receiver 

The receiver have the following functions:
  • vw_set_tx_pin(pin); This function just set the receiver pin. The default pin it's 11.
  • vw_setup(uint16_t speed); is used to set the speed of the communication. It must be the transmitter speed.
  • vw_rx_start(); You must call it before receive any data.
  • vw_have_message(); Returns true if message has been received. This is similar to the "available" function of most other libraries.
  • vw_wait_rx();Wait for a message to be received. This will only return when a message has been received, otherwise it will wait forever, and the  program won`t continue. 
  • vw_wait_rx(timeout_ms); In this case the arduino will wait until the time waiting is more than the max time that you set.
  • vw_get_message(buf, &buflen) This function is used to store the message in a string. Buf is the name of the string and buflen is name of the variable that store the maximum size of the string.Then when you need data you take from buf.
  • vw_rx_stop() Disable the receiver process. 
// receiver.pde
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $

#include <virtualwire.h>


void setup()
{
    Serial.begin(9600); // Debugging only
    Serial.println("setup");

    // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);  // Bits per sec

    vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &amp;buflen)) // Non-blocking
    {
 int i;

        digitalWrite(13, true); // Flash a light to show received good message
 // Message with a good checksum received, dump it.
 Serial.print("Got: ");
 
 for (i = 0; i &lt; buflen; i++)
 {
     Serial.print(buf[i], HEX);
     Serial.print(" ");
 }
 Serial.println("");
        digitalWrite(13, false);
    }
}
Now what?
With this code you will be able to send string of data, but if you try to send a variable you will see that the Arduino IDE print some errors. In the next tutorial we will learn how to send multiple variables using Virtualwire.


Monday, August 19, 2013

Tutorial: Arduino + Kit rf 433Mhz(Part 2: Set up)

Today we are making the setting up for our RF link kit. If you don't now what's it an RF link kit please read the part 1 of this tutorial. So let's start then:


Software Set Up


Arduino Folder
First of all we have to install the library Virtualwire on the arduino IDE. We have to open a folder named "libraries" and copy the folder VirtualWire, that you download before, inside. This folder is in the arduino folder where the program files are kept. Then we have to restart the arduino IDE. Let's prepare the hardware.


Transmitter Set Up


Transmitter
First we going to set up our transmitter. In my case I will use an arduino Uno. We only need to connect the pin 12 from your arduino to the transmitter data pin. You have to look the data sheet because in function of the manufacturer the collocation of the pins could change.

If you want to have good range you should connect the transmitter to a 9v battery. This modules can be powered between 3 to 12 V. More volts means more range.If you use more than one battery you must connect the grounds, if not it won't work.

Antenna
Also, you have to put an antenna. For this modules a simple piece of wire with 15 cm long will be enough. I found some antennas for this modules, so another option it's to buy the antenna.I couldn't try them yet.


Receiver Set Up


Receiver
However, we have to connect the receiver. The connection it's similar. You have to attach the date pin to the pin 11 on your arduino board  and power the receiver. In this case you can power directly from your arduino because the receiver works with 5v. Also, you should put an antenna, the same as the transmitter will be enough.

Equal to the transmitter, the receivers from different manufactures could have different pins distributions.


Test


 Now it's time to charge the code. To be sure that all works fine, we will charge the example code. They two code examples are   File =>Examples=> VirtualWire=> transmitter   and    File => Examples=> VirtualWire=> receiver.

Then open the serial monitor and if you receive the data your set up it's correct.If not read "A tip for solve possible problems"

This all for this part of the tutorial, on the next part we will read the code and understand all the functions on the VirtualWire library. Leave some comments and propose ideas writing to controlrobotics@rodrigomompo.com


A tip for solving possible problems

A good form to test if the problem is form your code or from your hardware, its making the connection trough a wire. Again you need to make sure that all the grounds are connected if you want a positive result.

Saturday, August 17, 2013

Tutorial: Arduino + Kit rf 433Mhz (Part 1: Introdución)

When you start making  more complex projects, you will probably need to read a sensor far away from your arduino or read/send information between two arduinos. Sometimes you can use a piece of wire but when you can´t use it, you will need some wireless solutions.

Kit Link Rf 433 Mhz
There are a lot of options but many of theme could be a bit expensive for some projects. Instead, you can use an  RF link kit that cost about 3$  each!!. The most common frequency is 433 Mhz but you can find 315  Mhz kits as well. Whit this kits you can send data from one arduino to  another.

How a RF link kit works  ?


This kits use only one digital pin for transmitting (TX) and one pin for receiving  (RX) the data. So, you have to take the data from one arduino, convert it in a binary sequence of 0 and 1, send it and then  when you receive the binary sequence, transform it  in data.

In the next part of this tutorial,we will start setting up the hardware and programing the software. For the next part of the tutorial you will need:

Prototyping wire Male/Female
Hardware

  • Two arduinos 
  • Kit Rf 433 MHz 
  • Some wire 
  • Two breadboards or prototyping  wire to connect the TX and RX module to the arduino
Software
  • Arduino IDE
  • Library VirtualWire

Welcome to ControlRobotics

Today, I'm starting a new project. In this blog I will try to resolve common problems that arise while you are  developing your home projects. Furthermore, I will post some interesting projects to do in your free time and other interesting information about  DIY electronics. However, I would like to post finished DIY projects from the followers and other interesting stuff. So you can propose your ideas and projects on google+ or send it to  controlrobotics@rodrigomompo.com.