lundi 7 avril 2014

Sending SMS with Android


This is a quick example on how to integrate the SMS your app. Threre are two ways to do it:
  • Programmatically
public void SendSms(string phoneNumber, string smsMessage){

         SmsManager mySmsManager = SmsManager.getDefault();

         mySmsManager .sendTextMessage(phoneNumber, null, smsMessage, null, null);

}
  • Using the built in Android SMS Application 

public void builtINSMS(string phoneNumber,string message) {

        Intent intentSMS = new Intent(Intent.ACTION_VIEW);



        intentSMS.putExtra("sms_body", message);

        intentSMS.putExtra("address", phoneNumber);

        intentSMS.setType("vnd.android-dir/mms-sms");

        startActivity(intentSMS );

}


Don't forget to add Sending SMS permission in your manifest file

<uses-permission android:name="android.permission.SEND_SMS" />

mercredi 2 avril 2014

Arduino and Android ADK


Smartphones gives us a wide range of applications that help us organize our selves, play and wake up on time, but if only there is a way to connect our phones to the real world to control hardware stuff like house lighting system or the garage door. Smartphones have a bunch of possibilities including sensors like GPS, accelerometers and temperature, a decent cpu for processing data but the most important feature a smartphone can give is its portability.




In 2011 Google starts a project called Android ADK: http://accessories.android.com/ the Android accessory kit, that can make your phone communicate to devices (accessories) by make a bridge between the power of android devices and the real world through a simple USB communication. This bridge can solve so many problems :D



So I thought to try it out with an arduino ADK board. The project I've done is to control a led and a DC motor From the Android to the arduino passing by xbee modules.
The next diagram explains entities communication:


The code has three sides:

  • The Android side : sending commands through ADK
  • The Arduino ADK Side: Receiving commands and send it wirelessly to other arduino boards with xbee
  • The Arduino Uno Side: Receiving commands from xbee and control the DC motor and the led.
The hole project:

I'll  be happy to answer questions in the comments
Thanks.

dimanche 5 janvier 2014

2 DC MOTORS DRIVER with L298

Hi,
As I'm starting with CADSoft Eagle software, I wanted to make a simple 2 motor driver board.
This board can control 2 DC motors using the L298 circuit from ST.


You can find the complete data-sheet of the circuit here

The schematics:


The circuit:





samedi 4 janvier 2014

STM32F4 discovery board adapter parts with Eagle

The STM32F4 discovery is a wonderful board but it is really not freindly when testing with all its ugly male connectors that it is impossible to put it in a lab board.

I don't know if anyone did this before, but I made a small adapter in eagle for this board so it can be easily integrated with other test or prototyping project or it can be simply used in a hole PCB board.

Download the part from here:


 

Bipolar Stepper Motor with STM32

Hi,
Stepper motors are very commun in many applications, they are widely used in printers scanners and many other equipements thanks to their easy control.


I really advice you to understand how bipolar stepper works before testing the following code.
Start from here !

 The following code is for controlling a bipolar stepper motor using STM32F4 discovery board.
I used a l293D for power interface between the stepper and the board like the following image:


And The I used this simple code to control my stepper in one direction with fixed speed using half step control.

void GPIOD_Initialize(){
 GPIO_InitTypeDef GPIOD_Stepper;
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
 
 GPIOD_Stepper.GPIO_Mode = GPIO_Mode_OUT;
 GPIOD_Stepper.GPIO_OType = GPIO_OType_PP;
 GPIOD_Stepper.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_3|GPIO_Pin_5|GPIO_Pin_7;
 GPIOD_Stepper.GPIO_PuPd = GPIO_PuPd_NOPULL;
 GPIOD_Stepper.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_Init(GPIOD,&GPIOD_Stepper);
}


int main(void)
{
GPIOD_Initialize();
        while(1){
  GPIO_Write(GPIOD,GPIO_Pin_1); 
  Delay(100);
  GPIO_Write(GPIOD,GPIO_Pin_1| GPIO_Pin_3); 
  Delay(100);
  GPIO_Write(GPIOD,GPIO_Pin_3);
  Delay(100);
  GPIO_Write(GPIOD,GPIO_Pin_5|GPIO_Pin_3); 
  Delay(100);
  GPIO_Write(GPIOD,GPIO_Pin_5);
  Delay(100);
  GPIO_Write(GPIOD,GPIO_Pin_5|GPIO_Pin_7);
  Delay(100);
  GPIO_Write(GPIOD,GPIO_Pin_7);
  Delay(100);
  GPIO_Write(GPIOD,GPIO_Pin_7|GPIO_Pin_1);
  Delay(100);
         }
}



jeudi 2 janvier 2014

Timer with STM32F4

Hello,
This time I'll give you a short tutorial about how to use timers with the STM32.
Timers are very useful when it comes to make a precise period of time independantly from your main loop execution.


The stm32F4 has many timers each one with a specific need. I'm just going to use the Timer 2 to make an interruption each 0.25 sec.
I use a C# program to calculate what values to put in the prescaler and the periode to get my required interruption time.
https://www.mediafire.com/?bq21q5qd7frcvba

The code has comments in it but if there is something that is not clear explained in the comments below, I'll be happy to answer.


void TIM2_IRQHandler(void){
 static short i = 0;
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
 GPIO_WriteBit(GPIOD,GPIO_Pin_13,i++);
GPIO_ToggleBits(GPIOD, GPIO_Pin_14);
}
}

void INTTIM_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* Enable the TIM2 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
 
/* TIM2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* Time base configuration */

TIM_TimeBaseStructure.TIM_Period = 1000000 - 1; // 1 MHz down to 1 KHz (1 ms)
TIM_TimeBaseStructure.TIM_Prescaler = 43- 1; // 24 MHz Clock down to 1 MHz (adjust per your clock)
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* TIM IT enable */
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);
}

int main(void)
{

 STM_EVAL_LEDInit(LED3);
 STM_EVAL_LEDInit(LED4);
 STM_EVAL_LEDInit(LED5);
 STM_EVAL_LEDInit(LED6); 
 INTTIM_Config();
 while(1);
}