クロス開発しなくていいのがRaspberry Pi のいいところですが、コーディングをする際などにもたつきを感じたりすることがあります。そこで、ネット上でSambaの設定を調べて、Windowsパソコンとファイル共有できる状態にして、あらかたのコードを普段使っているWindowsの環境で作っておき、ビルド、実行、デバッグ、修正をRaspberry Pi上でやるような感じにしています。
今回のコードはこんなかんじです。Gordons ProjectsのWiringPiを使わしてもらっています。
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <wiringPi.h>
#include <lcd.h>
// Raspduino のピン定義。
#define PIN_RXD 16
#define PIN_TXD 15
#define PIN_D02 0
#define PIN_D03 1
#define PIN_D04 2
#define PIN_D05 3
#define PIN_D06 4
#define PIN_D07 5
#define PIN_D08 6
#define PIN_D09 7
#define PIN_D10 10
#define PIN_D11 12
#define PIN_D12 13
#define PIN_D13 14
#define PIN_SDA 8
#define PIN_SCL 9
#define PIN_LOW 0
#define PIN_HIGH 1
// LCD Shield のピン定義。
const int PIN_LCD_RS = PIN_D12;
const int PIN_LCD_E = PIN_D11;
const int PIN_LCD_D4 = PIN_D05;
const int PIN_LCD_D5 = PIN_D04;
const int PIN_LCD_D6 = PIN_D03;
const int PIN_LCD_D7 = PIN_D02;
// LCD関連定数の定義。
const int LCD_ROW_NUM = 2;
const int LCD_CLM_NUM = 16;
const int LCD_MODE_4BIT = 4;
int main(int argc, char **argv)
{
int lcd;
// WiringPi 初期化。
if (wiringPiSetup() == -1) exit(1);
// LCD初期化。
lcd = lcdInit(LCD_ROW_NUM, // LCD行数。
LCD_CLM_NUM, // LCDカラム数。
LCD_MODE_4BIT, // 4bitモード。
PIN_LCD_RS, // RS
PIN_LCD_E, // E
PIN_LCD_D4, // 以下データピン
PIN_LCD_D5,
PIN_LCD_D6,
PIN_LCD_D7,
0, 0, 0, 0);
if (lcd == -1)
{
printf("LCD Initialize Error\n");
return 1;
}
sleep(1);
lcdPosition(lcd, 0, 0);
lcdPuts(lcd, "Hello,Raspberry!");
lcdPosition(lcd, 0, 1);
lcdPuts(lcd, "Raspduino!!");
return 0;
}
Raspduino (Raspberry Pi GPIOコネクタ ←→ Arduino ピン配置変換)アダプタが思ったよりも使えそうなので、回路図(というのは恥ずかしすぎるものですが)的にはこんな感じです。
要はRaspberry Pi のGPIOを ロジックレベル変換モジュール(自分は秋月の双方向ロジックレベル変換モジュールを使いました)とI2Cレベル変換モジュール(自分は秋月のI2Cレベル変換モジュールを使いました)でRaspberry Pi側3.3VとArduino側コネクタを切り離し(変換)しています。Arduino側はジャンパの切り替えで外部電源とRaspberry Piの5V(USBコネクタからの給電)を切り替えられるようにしています。ピンマッピング等の検討はこんな感じ。



0 件のコメント:
コメントを投稿