Magnetic Card lock with the Arduino

February 17th, 2010 Thomas Jespersen No comments

I have posted alot of projects recently, and here is another project with the Arduino!
This projects is about making a magnetic card lock using the Arduino, a servo and a $4 cheap magnetic card reader from AllElectronics.com

Magnetic Card Lock project


Magnetic Card Reader Connections

The card reader, which you can see in the first picture, has 7 pins. The picture below shows theese pins functionality!

I’ve made a video about the project which explains it all!

If you want to try it yourself, you can grab the code underneath and change the checkCode character array to match the string on your card!

#include <string.h>

#include <Servo.h>
Servo servo1;

 /* Magnetic Card lock with the Arduino and servo's
 * by Thomas Jespersen http://elec.tkjweb.dk
 *
 * Reads a magnetic stripe and opens lock (turns servo) if card is the same as programmed
 *
 */

// Connections: DATA = Pin 2, CLOCK = Pin 3, CARD IN = Pin 5
// See PDF "Magnetic Stripe Card Reader! << HACKMIAMI.pdf" for more connection information

Read more...

STM32 – Overclocking

February 14th, 2010 Thomas Jespersen 6 comments

Have you ever wondered if it was possible to overclock the STM32? It is, with a simple change in code line!
We only have to change the PLL setting, which is able to go up to 16 – so that means that we can overclock the STM32 up to 8MHz x 16 = 128 MHz
Here is the RCC Initialization code for 128MHz – remember, you also have to comment the “SYSCLK_FREQ_72MHz”, uncomment the “SYSCLK_FREQ_HSE” and set it to 128MHz in the system_stm32f10x.c

/*******************************************************************************
* Function Name  : RCC_Configuration
* Description    : Configures the different system clocks.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void RCC_Configuration(void)
   {
   /* RCC system reset(for debug purpose) */
   RCC_DeInit();

   /* Enable HSE */
   RCC_HSEConfig(RCC_HSE_ON);

   /* Wait till HSE is ready */
   HSEStartUpStatus = RCC_WaitForHSEStartUp();

   if(HSEStartUpStatus == SUCCESS)
      {
      /* Enable Prefetch Buffer */
      FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

      /* Flash 2 wait state */
      FLASH_SetLatency(FLASH_Latency_2);

      /* HCLK = SYSCLK */
      RCC_HCLKConfig(RCC_SYSCLK_Div1); 

      /* PCLK2 = HCLK */
      RCC_PCLK2Config(RCC_HCLK_Div1); 

      /* PCLK1 = HCLK/2 */
      RCC_PCLK1Config(RCC_HCLK_Div2);

      /* PLLCLK = 8MHz * 9 = 72 MHz */
      //RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
      /* PLLCLK = 8MHz * 16 = 128 MHz */
      RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_16);
      // The frequency has also been changed in system_stm32f10x

      /* Enable PLL */
      RCC_PLLCmd(ENABLE);

      /* Wait till PLL is ready */
      while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
         {;}

      /* Select PLL as system clock source */
      RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

      /* Wait till PLL is used as system clock source */
      while(RCC_GetSYSCLKSource() != 0x08)
         {;}
      }

   /* Enable peripheral clocks --------------------------------------------------*/
   /* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC
         | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG
         | RCC_APB2Periph_AFIO, ENABLE);
   }
Categories: ARM Projects Tags: , ,

STM32 – Internal 8MHz Clock Setup Routine

February 10th, 2010 Thomas Jespersen No comments

Here is the setup code to use the internal 8MHz clock – but with the internal clock, we are only able to get a max frequency of 36MHz.

void clock_init(){
  /*Configure all clocks to max for best performance.
   * If there are EMI, power, or noise problems, try slowing the clocks*/                     

  /* First set the flash latency to work with our clock*/
  /*000 Zero wait state, if 0  MHz < SYSCLK <= 24 MHz
    001 One wait state, if  24 MHz < SYSCLK <= 48 MHz
    010 Two wait states, if 48 MHz < SYSCLK <= 72 MHz */
  FLASH_SetLatency(FLASH_Latency_1);                                                         

  /* Start with HSI clock (internal 8mhz), divide by 2 and multiply by 9 to
   * get maximum allowed frequency: 36Mhz
   * Enable PLL, wait till it's stable, then select it as system clock*/
  RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_9);
  RCC_PLLCmd(ENABLE);
  while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {}
  RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);                                                 

  /* Set HCLK, PCLK1, and PCLK2 to SCLK (these are default */
  RCC_HCLKConfig(RCC_SYSCLK_Div1);
  RCC_PCLK1Config(RCC_HCLK_Div1);
  RCC_PCLK2Config(RCC_HCLK_Div1);                                                             

  /* Set ADC clk to 9MHz (14MHz max, 18MHz default)*/
  RCC_ADCCLKConfig(RCC_PCLK2_Div4);                                                           

  /*To save power, use below functions to stop the clock to ceratin
   * peripherals
   * RCC_AHBPeriphClockCmd
   */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_ALL, ENABLE);                                         

}
Categories: ARM Projects Tags:

320×240 Color Display – SSD2119

January 27th, 2010 Thomas Jespersen 26 comments

I finally got the display I bought on eBay to work. It took me a lot of hours as the man I’d bought the display from told me that the display controller was an ILI9320, so I started making code for the display like it was using an ILI9320 controller.

But as it didn’t work, I started debugging using my Raisonance RLink, and just when I looked at the Device variable – a variable which holds the controller number, and is loaded at the initialization process of the display, it showed me that it was an SSD2119 controller.

So I found the SSD2119 datasheet and started recoding using the new Command calls found in the datasheet… Finally it worked and showed some life :)

So right now I have a working SSD2119 code with SetPixel, Text, Circle, Rectangle, Fill and some working Touch Screen commands for the onboard ADS7843 touch screen controller.

Please take a look at this image to see the display in action:

SSD2119 seen from top

SSD2119 from top


SSD2119 Pringles example

The current GUI commands I’ve made is:
void Lcd_Text(u16 x, u16 y, u8 *str, u16 len,u16 Color, u16 bkColor);
void Lcd_Line(u16 x0, u16 y0, u16 x1, u16 y1,u16 color);
void Lcd_Circle(u16 cx,u16 cy,u16 r,u16 color,u8 fill);
void Lcd_Rectangle(u16 x0, u16 y0, u16 x1, u16 y1,u16 color,u8 fill); // Slower than Lcd_ColorBox
void Lcd_Square(u16 x0, u16 y0, u16 width, u16 color,u8 fill);
void Lcd_ClearCharBox(u16 x,u16 y,u16 color);
void Get320240PictureCode(u8* pBuffer,u32 BufferCounter,u32 BaseAddr);

void Lcd_FastRectangle(u16 x0, u16 y0, u16 x1, u16 y1,u16 color,u8 fill); // Faster than Lcd_Rectangle
void Lcd_FastSquare(u16 x0, u16 y0, u16 width, u16 color,u8 fill); // Faster than Lcd_Rectangle
void Lcd_FastClearCharBox(u16 x,u16 y,u16 color);

void DispPic320_240(const unsigned char *str);
void DispPic(u16 x0, u16 y0, const unsigned char *str);

DispPic320_240 and DispPic uses a byte array to show a image – the byte array is converted from a 24-bit .BMP (bitmap) file using a program I’ve made in Visual Basic .NET!

Categories: ARM Projects Tags: , , ,

Messy electronics table

January 27th, 2010 Thomas Jespersen No comments

Messy Table

This is the table where I’m working with electronics when it’s messy!
But still I keep a little bit order, as the PIC is in the left, the STM32 in the middle, and the Arduino (+ ultrasonic) at the right.

Ultrasonic Range Sensor

January 27th, 2010 Thomas Jespersen 1 comment

Today I recieved a Ultrasonic Range Sensor bought on eBay.

It’s much like the Parallax Ping))), except that it has got a Trig and a Echo pin, instead of the Ping)))’s multipin (Trig and Echo on the same pin)

I quickly made some code in the Arduino IDE and got it running quick…

Just a sidenode from the physics class; as the sound is travelling thru air with a speed of 340 m/s, this can be recalculated to 0.034 cm/microsecond, which is the same as 29.411 microsecond/cm

Arduino with Ultrasonic Sensor

For those who may be interested the code is here:

/* Ultrasonic Sensor

This sketch reads a ultrasonic rangefinder and returns the
distance to the closest object in range. To do this, it sends a pulse
to the sensor to initiate a reading, then listens for a pulse
to return.  The length of the returning pulse is proportional to
the distance of the object from the sensor.

The circuit:
* +V connection of the Ultrasonic Sensor attached to +5V
* GND connection of the Ultrasonic Sensor attached to ground
* Trig connection of the Ultrasonic Sensor attached to digital pin 2
* Echo connection of the Ultrasonic Sensor attached to digital pin 3

created 25. Januar 2010
by Thomas Jespersen

*/
Read more...

STM32 Nokia LCD

January 27th, 2010 Thomas Jespersen No comments

Finally I found how to use the Nokia LCD I’ve bought from Sparkfun a year ago.
Originally I bought the display for the Arduino, but as the LCD is 3.3V I tried to make a voltage convertion circuit, but it didn’t work :(
But now, I’ve got the STM32 which is running 3.3V – so I could just connect it directly… And then it worked!

Nokia LCD - Hello World


Nokia LCD - TKJ-Electronics Logo

Categories: ARM Projects Tags: , ,

STM32 DFU Programming

January 25th, 2010 Thomas Jespersen 2 comments

The time is currently 21:42 and I’ve been sitting in front of my computer in 2 hours to get the DFU programming to work.

Now it is working, and I’m able to make one of my excisting projects into a DFU loadable project (compiled it’s a .dfu filed)

I’ve also changed the DFU bootloader code to use GPIOA_0 as DFU Enable pin, and GPIOA_1 as USB Disconnect – this makes me able to use the GPIOB and GPIOC for my display without any interferrance!

Here is how you make a Ride7 project DFU loadable:

The Default Startup script (in settings) has been set to No, as we have included a special startup script in the project (startup_stm32f10x_hd.s – found in CMSIS\Core\CM3\startup\gcc)
Also change the Linker Script in project settings to match the processor group you are using (Connectivity, High Density… and so on – fx stm32f10x_hd_flash_offset.ld)
Also be aware of the change in the NVIC_Configuration – here we tell the processor that the Flash has to start at adress 0×3000
When you have compiled the code to a HEX file, run “DFU File Manager” to create a .dfu file.
Target ID: 00 is Internal Flash
Target ID: 01 is SPI Flash
Target ID: 02 is NOR Flash
Now you can use DfuSe to load the .dfu file into the internal flash of your STM32!
Categories: ARM Projects Tags: ,

STM32 USB Connection

January 25th, 2010 Thomas Jespersen No comments

The USB connection between the STM32 and the computer is finally working.
I’ve tried the different USB programs from the StdPeriph Library

Fx.

  • Virtual COM Port
  • DFU Programming

As I’m using Ride7 for programming, I can upload the project and sources if you want me too.

 

OBS: If you have projects which DOESN’T use the USB, you have to set the USB Disconnect jupmer to Ground (Pos. 1-2), as if not, the STM32 will stop in some kind of USB Interrupt trying to make a data communication with the computer, but it never comes as the STM32 doesn’t start one!

I discovered this  when I tried DFU’ing my 320×240 LCD code – and when I went back to normal .hex, it didn’t work – that was because I had to set the USB Disconnect to Ground!

Categories: ARM Projects Tags: , , ,

STM32 Peripheral Notes

January 18th, 2010 tlied2 No comments

Got some sensors hooked up to my header board.
The code is ugly and needs work, but gets data from stuff.

UART1@115200 = ft232 USB adapter (todo change to internal usb) – for debugging
UART2@9600 = SFE 16×2 SerLCD (For Display)
I2C1@100KHz = TMP102 (temperature) and HMC6352 (compass)

TMP102:

Compatible with LM75
TIe ADD0 to GND for default address 0×90
I just grabbed the LM75 stuff from ST’s STM32103B EVAL Demo kit (tsensor.h/c) and ripped out the LCD stuff – TODO work on formatting, return types, etc

HMC6352:

Get Heading: Send 0×41 (‘A’) and read in two bytes of data / 10 for decimal degrees

I think I like I2C, this was all entirely too easy :)

TODO: Improvements so maybe I can post some code, and should do a driver for the ADXL345 accelerometer.

New Gyro, Cam, LCD on the way to figure out as well.

Categories: ARM Projects Tags: