Go Down

Topic: Controll Arduino over serial with Linux shell script / Read Value out (Read 5 times) previous topic - next topic

tchleb

Hi,

i try to controll an Arduino with serial Connection on Linux. Im also want to read out some Values.
But in the shell Script is somethin wrong, what ist the falture?


Quote
#include "U8glib.h"  //https://code.google.com/p/u8glib/

  #include <OneWire.h>

 #include <DallasTemperature.h>

 #define ONE_WIRE_BUS 3   //OWB an PIN 3

 OneWire oneWire(ONE_WIRE_BUS);

 DallasTemperature sensors(&oneWire);

 DeviceAddress sensor1 = { 0x28, 0xFF, 0x19, 0x8B, 0x4C, 0x04, 0x00, 0x3B };
 
 DeviceAddress sensor2 = { 0x28, 0xFF, 0x12, 0x8B, 0x4C, 0x04, 0x00, 0x4B };







   U8GLIB_SSD1306_128X64_2X u8g(U8G_I2C_OPT_NONE);     //Banggood SSD1306 0.96" OLED I2C     http://www.banggood.com/0_96-Inch-White-IIC-I2C-OLED-Display-Module-12864-LED-For-Arduino-p-932606.html

                                                       //SDA = Pin A4 ; SCL = PIN A5

                                                     



  double temp1 = 0;

  double temp2 = 0;

  int led = 13;

 

  void u8g_prepare(void)

  {

  //u8g.setFont(u8g_font_6x10);

  //u8g.setFont(u8g_font_fub42n);

  //u8g.setFontRefHeightExtendedText();

  //u8g.setDefaultForegroundColor();

  //u8g.setFontPosTop();

  }





void setup(void)

{

    Serial.begin(9600);

 pinMode(led, OUTPUT);  //PIN 13 (LED) als Ausgang definieren

    sensors.begin();  //DallasTemperature sensoren starten

    u8g.setRot180();     // Display um 180° grehen, wenn erforderlich

 

  //u8g.setContrast(0x30);

  //u8g_prepare(); 





 }



void draw(void)

{   

 

    //oben

    u8g.setFont(u8g_font_fub17n);

    u8g.setPrintPos(0, 20);

    u8g.print(temp1);

    u8g.setFont(u8g_font_fub17);

    u8g.drawStr( 75, 20, "C");



   

     //unten

    u8g.setFont(u8g_font_fub17n);

    u8g.setPrintPos(0, 50);

    u8g.print(temp2);

    u8g.setFont(u8g_font_fub17);

    u8g.drawStr( 75, 50, "C");



       

 

}





void serialcontrol()

{
  int eingabe = 0;
  eingabe = Serial.read();    // seriell einlesen

   //Sensor2 bei eingabe 2 ausgeben

  if (eingabe == '1' )

      {



 Serial.print("Temperatatur Sensor1: ");

 //Serial.println(sensors.getTempCByIndex(sensor1));   
       Serial.println(temp1);   

      }

   

   //Sensor2 bei eingabe 2 ausgeben

  if (eingabe == '2' )

      {


 Serial.print("Temperatatur Sensor2: ");
 //Serial.println(sensors.getTempCByIndex(sensor2));   
       Serial.println(temp2);   

      }

 

    if (eingabe == '3' ) //LED an 13 einschalten

      {
 digitalWrite(led, HIGH);
      } 

 
  if (eingabe == '4' ) //LED an 13 ausschalten

      {
 digitalWrite(led, LOW);
      } 

}







void loop(void)

{

 

  sensors.requestTemperatures();

  // temp = sensors.getTempCByIndex(0); //Sensor ohne Adressierung

  temp1 = sensors.getTempC(sensor1);

  temp2 = sensors.getTempC(sensor2);



 



  // picture loop

  u8g.firstPage();

  do

  { 

    draw();
 serialcontrol();


  }

  while( u8g.nextPage() );

  delay(450); //0.45sekunden

  }

When i try manually-->

Code: [Select]
root@debian:/tmp# echo '2' > /dev/ttyACM0
root@debian:/tmp# echo '1' > /dev/ttyACM0


then i get the right answear -->

Code: [Select]
root@debian:/tmp# cat /dev/ttyACM0
Temperatatur Sensor2: 16.62
Temperatatur Sensor1: 16.69



When i try it automatically with a shell script (with 755 rights). The .txt file is empty.
What make im wrong?

Code: [Select]
#!/bin/bash

echo '1' > /dev/ttyACM0
cat /dev/ttyACM0 > /tmp/sensor1.txt
sleep60
echo '2' > /dev/ttyACM0
cat /dev/ttyACM0 > /tmp/sensor2.txt
exit


greats
Tobi

Go Up