LoginSignup
2
0

More than 1 year has passed since last update.

Spresense Mainボードで カメラサンプル を動かしました

Last updated at Posted at 2022-10-19

Spresense の Arduino IDE のCamera Sample(Spresense_camera_preview.ino)
をMainboardのSPIと自作のLCD Driverボード、それからST7789をコントローラーに使ったLCDで動かしました。

Spresense_camera_preview.inoの動作環境は
Spresense メインボード
Spresense 拡張ボード
Spresense カメラボード
ILI9341をコントローラーに使用しているLCDボード
となっています。

拡張ボードにLCDを接続する構成となっているために SPI4 を使用するようになっているので
これをMainボードの SPI5 を使うように変更しました。

今回の構成は以下のようになります。
Spresense メインボード
自社製LCDドライバーボード
Spresense カメラボード
ST7789をコントローラーに使用しているLCDボード

過去に書いている記事も参考にしてください。
Sony Spresense(IDE) で TFT LCD を動かしてみた
Sony Spresense(IDE) で TFT LCD を動かしてみた 2
SONY Spresense用 TFT LCDドライバーボード

先ずは
Spresense_camera_preview.ino)
こちらからペースとする、ソースコードをダウンロードします。

このソースコードをベースにLCDドライバーをILI9341からST7789に変更します。
なお、次の2つのライブラリを事前にセットアップしてください。
Adafruit-GFX-Library
Adafruit-ST7735-Library
ILI934-LibraryはSpresense用にカスタマイズされたバージョンが必要みたいですが
Adafruit-ST7735-Libraryは変更無しでそのまま使えます。

以下が変更したコードです

Spresense_camera_preview.ino
/*
 *  Spresense_camera_preview.ino - Simple camera preview example application
 *  Copyright 2019 Sony Semiconductor Solutions Corporation
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */


#include <Camera.h>
#include <SPI.h>
#include <Adafruit_GFX.h>    // Core graphics library
// #include "Adafruit_ILI9341.h"
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789

// #define TFT_RST 8
// #define TFT_DC  9
// #define TFT_CS  10

#define TFT_CS        2
#define TFT_RST       18
#define TFT_DC        26

//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS ,TFT_DC ,TFT_RST);
Adafruit_ST7789 tft = Adafruit_ST7789(&SPI5,TFT_CS, TFT_DC, TFT_RST);

void CamCB(CamImage img){
  if (img.isAvailable()) {
    img.convertPixFormat(CAM_IMAGE_PIX_FMT_RGB565);
    tft.drawRGBBitmap(0, 0, (uint16_t *)img.getImgBuff(), 320, 240);
  }
}

void setup() {

  // tft.begin();
  tft.init(240, 320);           // Init ST7789 320x240
  tft.setRotation(3);

  theCamera.begin();
  theCamera.startStreaming(true, CamCB);

}

void loop() {
  // put your main code here, to run repeatedly:
}

変更箇所は
インクルードファイルの変更
制御信号のピン設定
LCDドライバーの初期化関数
tft.begin(); を tft.init(240, 320); に変更
となります。
Adafruit_ST7789(&SPI5,TFT_CS, TFT_DC, TFT_RST);
ここで使用するSPIポートにメインボードのSPI5を指定しています。

これでこれでメインボードでカメラサンプルのプログラムを実行できます。

写真の出来が良くないですがこんな感じで動いています。
IMG-0769.jpg

こちらも分かり辛いですがこのようにコンパクトになります。
IMG-0770.jpg

今回はST7789を使ったLCDを動かしましたが、次回はILI9341を使ったLCDを動かしてみようと思っています。
また、現在 Spresense SDK を使ったカメラサンプルも、メインボードのSPI5を使って動かす実験をやっています。
動くには動いたのですが、カメラのコントラスト調整が悪いのか、画面がほぼ真っ白になっていますのでもう少し検証してから記事にする予定です。

なお今回使用しているLCDドライバーボードに関してはお問合せください。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0