admin

admin

This demonstration (writing string to EEPROM) adopted the code from Arduino Playground and I  had removed some of the features to make it simple and easy to understand.
 
 
Code below demonstrate how to write strings to EEPROM at specified location(address) and then read it back.
Thursday, 18 April 2013 22:26

读取和写入任何结构EEPROM

Arduino内建的EEPROM函数(function)毎次只支能写入一个字节(one byte),一个英文字母或者整数从0到255。当想要写入较大的数字时,唯有调用多次的EEPROM函数,从而造成代码复杂以及难于调试。
 
使用下面的代码,只需一次EEPROM函数调用,任何数据结构或变数都可以一一写入及读取。保存以下代码至文件名为EEPROMAnything.h

#include <EEPROM.h>
#include <Arduino.h> // for type definitions

template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
   const byte* p = (const byte*)(const void*)&value;
   unsigned int i;
   for (i = 0; i < sizeof(value); i++)
   EEPROM.write(ee++, *p++);
   return i;
}

template <class T> int EEPROM_readAnything(int ee, T& value)
{
   byte* p = (byte*)(void*)&value;
   unsigned int i;
   for (i = 0; i < sizeof(value); i++)
   *p++ = EEPROM.read(ee++);
   return i;
}

 

 

一旦有了以上文件,编写程序前只要添加#include "EEPROMAnything.h"就能调用 EEPROM_writeAnything 和 EEPROM_readAnything函数了。请看以下例子:
#include <EEPROM.h>
#include "EEPROMAnything.h"
struct config_t
{
    long alarm;
    int mode;
} configuration;
void setup()
{
    EEPROM_readAnything(0, configuration);
    // ...
}
void loop()
{
    // let the user adjust their alarm settings
    // let the user adjust their mode settings
    // ...
    // if they push the "Save" button, save their configuration
    if (digitalRead(13) == HIGH)
        EEPROM_writeAnything(0, configuration);
}
  
当然也可以使用avr的eeprom程序库来代替以上EEPROMAnything.h

#include <avr/eeprom.h>

struct settings_t
{
  long alarm;
  int mode;
} settings;

void setup()
{
  eeprom_read_block((void*)&settings, (void*)0, sizeof(settings));
    // ...
}
void loop()
{
    // let the user adjust their alarm settings
    // let the user adjust their mode settings
    // ...

    // if they push the "Save" button, save their configuration
    if (digitalRead(13) == HIGH)
      eeprom_write_block((const void*)&settings, (void*)0, sizeof(settings));
}

Tuesday, 16 April 2013 21:05

Arduino and Stronglink SL018 RFID module

Stronglink SL018 RFID module
Among the RFID modules, Stronglink SL018 is the lowest cost RFID module that I can get which supports read and write. SL018 is a 13.56MHz RFID module, it supports Mifare 1K, Mifare 4K and Mifare Ultralight. The specification are as follow:
Model
MIFARE Module SL018
Frequency
13.56MHz
Protocol
ISO14443A
Tag supported
Ultralight, NTAG203, MIFARE Mini, MIFARE ™ Classic 1K, 4K MIFARE Classic ™, FM11RF08
Interface
I2C
Supply voltage
4.4 - 7.0VDC
Dimension
65 × 45 mm

To communicate with Arduino, Marc Boon had developed the SL018 library for Arduino which support reading UID of tags and reading/writing tags.
Sunday, 14 April 2013 21:10

Arduino读取键盘

Arduino and Keypad
这里提供两种方式从Arduino读取键盘。第一种方式是使用矩阵式(Matrix)键盘,另一种方式是使用PS2键盘。
 
矩阵键盘(Matrix keypad)
首先必须安装Arduino Keypad键盘库(Keypad library),Arduino Keypad键盘库可以从Arduino Playground下载。Arduino Keypad键盘库让你读取矩阵式键盘而不用编写复杂的代码,此键盘库可以读取3x4, 4x4以及各种矩阵结构的键盘。
Saturday, 13 April 2013 16:47

Arduino与Stronglink SL018 RFID模块

Stronglink SL018 RFID module

眾多RFID模块中,Stronglink SL018是我找到最便宜的模块且支持读取及写入。SL018 使用了I2C接口(只使用两条信号线)与外界沟通,支持的RFID卡包括MIFARE Classic 1K, MIFARE Classic 4K 和 MIFARE Ultralight,频率则是13.56MHz。以下是SL018规则说明:
Model
MIFARE Module SL018
Frequency
13.56MHz
Protocol
ISO14443A
Tag supported
Ultralight, NTAG203, MIFARE Mini, MIFARE™ Classic 1K, MIFARE™ Classic 4K, FM11RF08
Interface
I2C
Supply voltage
4.4 - 7.0VDC
Dimension
65 × 45 mm
由于Marc Boon已经编写好了SL018用于 Arduino 程序库(Library)Arduino与SL018进行沟通将会变得非常的容易,只须几行代码,就能读取RFID卡的UID了。 
Monday, 11 February 2013 10:39

Resizing SD card partitions for Raspberry Pi

If you download the Raspbian image from Raspberry Pi official homepage and write it to the SD card, the SD card partition is fixed to 2GB, meaning that only 2GB is accessible no matter how big your SD card are. You must manually re-size the SD card partition in order to increase the available storage capacity.

Sunday, 10 February 2013 19:03

Develop Android Application without Coding

App Inventor is an application use to develop Android application without programming. Its graphical interface is very similar to Scratch   that allow users to drag and drop visual objects to develop application which runs on many mobile devices.

Google released App Inventor on  December 15, 2010 and terminated as the Google product on August 2011. App Inventor is maintained by Massachusetts Institute of Technology and the code is become "Open Source".
Sunday, 03 February 2013 18:35

Backing Up Raspberry Pi SD card

  • Insert SD card to computer
  • Launch Win32 Disk Imager
  • Select Device (source) which you want to backup from
  • Under Image File, give it a file name as shown in figure below
Backup Raspberry Pi SD card
 
  • Click Read button to start backing up
  • As shown in figure below, the image file size is equivalent to the size of SD card since I had resized the partition of my SD card
After Backup
Sunday, 03 February 2013 13:25

Running raspi-config anytime anywhere

Raspi-Config is a tool to help you to configure Raspberry Pi, it is a bit similar to adjust the computer BIOS settings. Raspi-config runs automatically when you boot your Raspberry Pi and you can access this tool anytime anywhere.
 
SSH to Raspberry Pi and enter command below

sudo raspi-config

 

 

Monday, 28 January 2013 23:20

Gambas for Raspberry Pi

Gambas is a BASIC interpreter which is very similar to Visual Basic but running on Linux. Gambas from version 3.2 can run on Raspberry Pi and Gambas3 for Raspberry Pi image file is available here.
 
 
Installation
  • After download the image file (it is zipped), extract it to any location of computer. Now your computer should have an image file named as 2012-07-15-wheezy-gambas3.img
  • Write this img file to SD card using Win32DiskImager as describe in this article
  • Remove the SD card from computer once writing completed
  • Insert the SD card to Raspberry Pi & power on it.
  • Remote access to Raspberry using TightVNC as describe in this article
  • You should see Gambas icon appear on the desktop screen.
  • To start Gambas3, click the first icon at the left bottom screen then select Programming>Gambas3

People find that they are facing 100% CPU usage when using Gambas3, you can use the patch to overcome this problem.

Back to Top