前提・実現したいこと
タッチセンサーを長押しした際に、BT通信されていれば熱電対(2セット)の値をBLEで送信するシステムを試作しています。
発生している問題・エラーメッセージ
BT通信をせず、シリアル通信だけの場合は値が上手く読み取れています。
が、BT通信をさせると熱電対の値が2つとも"0.00"になってしまいます。
■ハードウェア構成
・マイコンボード: Adafruit Feather 32u4 Bluefruit LE
・熱電対モジュール: MAX31856搭載 熱電対アンプモジュール
・タッチセンサー: AT42QT1011 静電容量式タッチセンサ
該当のソースコード
ArduinoIDE
1#include <SPI.h> 2 3#include "Adafruit_BLE.h" 4#include "Adafruit_BluefruitLE_SPI.h" 5#include "Adafruit_MAX31855.h" 6 7#define BLUEFRUIT_SPI_CS 8 8#define BLUEFRUIT_SPI_IRQ 7 9#define BLUEFRUIT_SPI_RST 4 10 11#define MAXDO 14 12#define MAXCS1 5 13#define MAXCS2 6 14#define MAXCLK 15 15 16// initialize the Thermocouple 17Adafruit_MAX31855 thermocouple_1(MAXCLK, MAXCS1, MAXDO); 18Adafruit_MAX31855 thermocouple_2(MAXCLK, MAXCS2, MAXDO); 19 20// Constants 21const int TOUCH_BUTTON_PIN = 9; // Input pin for touch state 22const int LED_PIN = 13; // Pin number for LED 23 24// Global Variables 25char inByte = 0; 26int buttonState = 0; // Variable for reading button 27int val = 0; 28int time = 0; 29int once = 0; 30int lastVal=LOW; 31int touch; 32double c1,c2; 33 34Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST); 35 36void setup() { 37 Serial.begin(115200); 38 39 ble.begin(true); //true => debug on, you can see bluetooth in the serial monitor. 40 ble.echo(false); 41 ble.factoryReset(); //Optional 42 ble.setMode(BLUEFRUIT_MODE_DATA); 43 44 pinMode(TOUCH_BUTTON_PIN, INPUT); 45 pinMode(LED_PIN, OUTPUT); 46} 47 48void loop(){ 49 val = digitalRead(TOUCH_BUTTON_PIN); 50 if (val == HIGH) { /* スイッチが押されている(押され続けている) */ 51 time++; 52 lastVal=HIGH; 53 delay(1); 54 } 55 else { 56 if(lastVal==HIGH && !once){ //直前はHIGHだった、つまりスイッチが離された。しかも、長押し処理されていない=長押し時間まで押され続けられなかった=短押しが完了したところである 57 if(time > 50){ //接点のバタつき(チャタリング)時間を超えて安定して押されていた 58 touch = 0; 59 } 60 } 61 lastVal=LOW; 62 time = 0; 63 once = 0; //もう一度送信できるように 64 } 65 if (time > 400) { //長押しif文 66 time = 401; 67 if (!once) { 68 touch = 1; 69 once = 1; //連続で送信されないように 70 thermoCouple(); //BLE送信前に値が出ているか確認用 71 bleSend(); 72 } 73 } 74} 75 76void bleSend() { 77 if(ble.isConnected()){ 78 thermoCouple(); 79 Serial.print("100");Serial.print(","); //データ確認用 80 Serial.print("1");Serial.print(","); //データ確認用 81 Serial.print(c1);Serial.print(","); //データ確認用 82 Serial.println(c2); //データ確認用 83 84 ble.print("100");ble.print(","); 85 ble.print("1");ble.print(","); 86 ble.print(c1);ble.print(","); 87 ble.println(c2); 88 } 89} 90 91void thermoCouple() { 92 93 c1 = thermocouple_1.readCelsius(); 94 c2 = thermocouple_2.readCelsius(); 95 96 Serial.print(c1);Serial.print(","); //データ確認用 97 Serial.println(c2); //データ確認用 98 99}
試したこと
■Serial.printの"c1"、"c2"は全て"0.00"
■テキスト情報の"1"、"100"はシリアル通信、BLE通信ともに正常に送信出来ている
■"ble.begin"を停止するとシリアル通信での"c1"、"c2"は正常な値が見られる
補足情報(FW/ツールのバージョンなど)
■特記事項なし
回答1件
あなたの回答
tips
プレビュー