a.binder před 5 roky
rodič
revize
e58253cde6

+ 31 - 0
SE/stuff/P5_Automation_can-dev-res-working-1930/___SUBMODULES___/LEDpwm/LEDpwm.ino

@@ -0,0 +1,31 @@
+
+#include <Wire.h>
+#include <Adafruit_PWMServoDriver.h>
+
+// called this way, it uses the default address 0x40
+Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
+
+
+
+void setup() {
+	Serial.begin(115200);
+	Serial.println("Test pwmled");  
+	pwm.begin();
+
+	  pwm.setOscillatorFrequency(270000);
+  pwm.setPWMFreq(160);  // This is the maximum PWM frequency
+      
+      pwm.setPWM(0, 0, 4000);
+
+      pwm.setPWM(7, 0, 4096);
+
+      pwm.setPWM(8, 0, 4000);
+      pwm.setPWM(15, 0, 4000);
+
+	
+}	
+
+
+void loop() {
+    	
+    	}

+ 138 - 82
SE/stuff/P5_Automation_can-dev-res-working-1930/___SUBMODULES___/gyro_and_compass_test/gyro_and_compass_test.ino

@@ -1,41 +1,77 @@
+//oled
 
-//radio
-#include <SPI.h>
-#include <nRF24L01.h>
-#include <RF24.h>
-RF24 radio(7, 10); // CE, CSN
-const byte address[6] = "00001";
 
+//#define HAS_18x4LCD
 
+#define HAS_u8x8log
 
-// #include "I2Cdev.h"
-#include "MPU6050.h"
 
+#if defined(HAS_u8x8log)
+    #include <Arduino.h>
+   // #include <U8g2lib.h>
+   #include <U8x8lib.h>
 
-//#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
-    #include "Wire.h"
-//#endif
+   
+   //U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // OLEDs without Reset of the Display
+   U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_NONE);
 
-#include <LiquidCrystal_I2C.h>
-LiquidCrystal_I2C lcd(0x27,16,4);  // set the LCD address to 0x27 or 0x20
+  // U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // All Boards without Reset of the Display
+            
+      #define U8LOG_WIDTH 16
+      #define U8LOG_HEIGHT 8
+      uint8_t u8log_buffer[U8LOG_WIDTH*U8LOG_HEIGHT];
+      U8X8LOG u8x8log;
 
+#endif
 
-//  #include "struct.h"
+#include "progmem__const.h"
+
+#define HAS_nRF24L01
 
-#include <QMC5883LCompass.h>
-QMC5883LCompass compass;
+//radio
+#if defined(HAS_nRF24L01)
+    #include <SPI.h>
+    #include <nRF24L01.h>
+    #include <RF24.h>
+    RF24 radio(7, 10); // CE, CSN
+const byte address[6] = "00001";
+#endif
 
+    #include "Wire.h"
 
-const int MPU=0x68; 
-int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
 
-MPU6050 accelgyro(MPU);
+#define HAS_MPU6050
+#if defined(HAS_MPU6050)
+// #include "I2Cdev.h"
+    #include "MPU6050.h"
+    //#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
+    #include "Wire.h"
+    //#endif
+#endif 
 
-  int16_t ax, ay, az;
-  int16_t gx, gy, gz;
-#define OUTPUT_READABLE_ACCELGYRO
-//#define OUTPUT_BINARY_ACCELGYRO
+    #if defined(HAS_18x4LCD)
+        #include <LiquidCrystal_I2C.h>
+        LiquidCrystal_I2C lcd(0x27,16,4);  // set the LCD address to 0x27 or 0x20
+    #endif
 
+//  #include "struct.h"
+#define HAS_QMC5883LCompass
+#if defined(QMC5883LCompass)
+    #include <QMC5883LCompass.h>
+    QMC5883LCompass compass;
+#endif
+
+#if defined(HAS_MPU6050)
+    const int MPU=0x68; 
+    int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
+    
+    MPU6050 accelgyro(MPU);
+    
+      int16_t ax, ay, az;
+      int16_t gx, gy, gz;
+    #define OUTPUT_READABLE_ACCELGYRO
+    //#define OUTPUT_BINARY_ACCELGYRO
+#endif
 
 #define LED_PIN 13
 bool blinkState = false;
@@ -43,88 +79,108 @@ bool blinkState = false;
  
 void setup()
 {
+    #if defined(HAS_u8x8log)
+        #include "u8g2__setup.h"
+    #endif
      //#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
-        Wire.begin();
+     //   Wire.begin();
     //#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
      //   Fastwire::setup(400, true);
     //#endif
+  
+    
+    
     Serial.begin(115200);
      while (!Serial); // Waiting for Serial Monitor
-    Serial.println("\nCompass ang gyro  test  ");      
+    //Serial.println("\nCompass ang gyro  test  ");
+    SPFT(title);  
+   
     #include "scan.h"
-
-    Serial.println("compass.init()");
-    compass.init();
-    Serial.println("accelgyro.initialize()");
-    accelgyro.initialize();
-    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
-     accelgyro.setMotionDetectionDuration(80);
-
+    #if defined(QMC5883LCompass)
+        Serial.println("compass.init()");
+        compass.init();
+    #endif
+    #if defined(HAS_MPU6050)
+        Serial.println("accelgyro.initialize()");
+        accelgyro.initialize();
+        Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
+         accelgyro.setMotionDetectionDuration(80);
+    #endif
     
     pinMode(LED_PIN, OUTPUT);
 
 //lcd.backlight();

 //lcd.setCursor(3,0);

 //lcd.print("Hello, world!");

-   #include "LiquidCrystal_I2C_setup.h"
+   #if defined(HAS_18x4LCD)
+        #include "LiquidCrystal_I2C_setup.h"
+    #endif
 // setZeroMotionDetectionThreshold(154);
 
-
-
-radio.begin();
-radio.openWritingPipe(address);
-radio.setPALevel(RF24_PA_MIN);
-radio.stopListening();
-
+ 
+#if defined(HAS_nRF24L01)
+    radio.begin();
+    radio.openWritingPipe(address);
+    radio.setPALevel(RF24_PA_MIN);
+    radio.stopListening();
+#endif
 
 }
  
 
 void loop()
 {
-   int x, y, z;
-Serial.println();
-  // Read compass values
-  compass.read();
-
-  x = compass.getX();
-  y = compass.getY();
-  z = compass.getZ();
-
-  Serial.print("Comp X: ");
-  Serial.print(x);
-  Serial.print("   Y: ");
-  Serial.print(y);
-  Serial.print("   Z: ");
-  Serial.print(z);
-
-    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
-   // these methods (and a few others) are also available
-    //accelgyro.getAcceleration(&ax, &ay, &az);
-    //accelgyro.getRotation(&gx, &gy, &gz);
-#ifdef OUTPUT_READABLE_ACCELGYRO
-        // display tab-separated accel/gyro x/y/z values
-        Serial.print("  a/g:\t");
-        Serial.print(ax); Serial.print("\t");
-        Serial.print(ay); Serial.print("\t");
-        Serial.print(az); Serial.print("\t");
-        Serial.print(gx); Serial.print("\t");
-        Serial.print(gy); Serial.print("\t");
-        Serial.print(gz);
-    #endif
 
-    #ifdef OUTPUT_BINARY_ACCELGYRO
-        Serial.write((uint8_t)(ax >> 8)); Serial.write((uint8_t)(ax & 0xFF));
-        Serial.write((uint8_t)(ay >> 8)); Serial.write((uint8_t)(ay & 0xFF));
-        Serial.write((uint8_t)(az >> 8)); Serial.write((uint8_t)(az & 0xFF));
-        Serial.write((uint8_t)(gx >> 8)); Serial.write((uint8_t)(gx & 0xFF));
-        Serial.write((uint8_t)(gy >> 8)); Serial.write((uint8_t)(gy & 0xFF));
-        Serial.write((uint8_t)(gz >> 8)); Serial.write((uint8_t)(gz & 0xFF));
+ // u8x8log.print("millis=");
+
+
+#if defined(QMC5883LCompass)
+      int x, y, z;
+   Serial.println();
+     // Read compass values
+     compass.read();
+   
+     x = compass.getX();
+     y = compass.getY();
+     z = compass.getZ();
+    SPFT(compass);
+    SPFT2(x,x);
+     Serial.print("   Y: ");
+     Serial.print(y);
+     Serial.print("   Z: ");
+     Serial.print(z);
+#endif
+#if defined(HAS_MPU6050)
+            accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
+           // these methods (and a few others) are also available
+            //accelgyro.getAcceleration(&ax, &ay, &az);
+            //accelgyro.getRotation(&gx, &gy, &gz);
+        #ifdef OUTPUT_READABLE_ACCELGYRO
+                // display tab-separated accel/gyro x/y/z values
+                Serial.print("  a/g:\t");
+                Serial.print(ax); Serial.print("\t");
+                Serial.print(ay); Serial.print("\t");
+                Serial.print(az); Serial.print("\t");
+                Serial.print(gx); Serial.print("\t");
+                Serial.print(gy); Serial.print("\t");
+                Serial.print(gz);
+            #endif
+        
+            #ifdef OUTPUT_BINARY_ACCELGYRO
+                Serial.write((uint8_t)(ax >> 8)); Serial.write((uint8_t)(ax & 0xFF));
+                Serial.write((uint8_t)(ay >> 8)); Serial.write((uint8_t)(ay & 0xFF));
+                Serial.write((uint8_t)(az >> 8)); Serial.write((uint8_t)(az & 0xFF));
+                Serial.write((uint8_t)(gx >> 8)); Serial.write((uint8_t)(gx & 0xFF));
+                Serial.write((uint8_t)(gy >> 8)); Serial.write((uint8_t)(gy & 0xFF));
+                Serial.write((uint8_t)(gz >> 8)); Serial.write((uint8_t)(gz & 0xFF));
+            #endif
+#endif
+    #if defined(HAS_18x4LCD)
+        #include "LiquidCrystal_I2C_loop.h"
+    #endif
+    #if defined(HAS_nRF24L01)
+        #include "radio_loop.h"
     #endif
-
-
-    #include "LiquidCrystal_I2C_loop.h"
-    #include "radio_loop.h"
   delay(1500);
 
 }

+ 24 - 0
SE/stuff/P5_Automation_can-dev-res-working-1930/___SUBMODULES___/gyro_and_compass_test/progmem__const.h

@@ -0,0 +1,24 @@
+
+
+#define FPr(x);   Serial.print(FP(x));              // FlashPrint(FT)
+#if defined(HAS_u8x8log)
+    #define SPFT(x);  u8x8log.print(FP(FT_##x));         // shorter version (ID)
+    #else
+    #define SPFT(x);  Serial.print(FP(FT_##x));         // shorter version (ID)
+#endif
+#define SFP(x);   Serial.print(FP(x));
+#define FT(x,y);  const char FT_##x[] PROGMEM = {y};// generate FlashText(ID,FT)
+#define FP(x)     (__FlashStringHelper*)(x)         // Helper
+
+#if defined(HAS_u8x8log)
+    #define SPFT2(x,y);  u8x8log.print(FP(FT_##x)); Serial.print("[");   Serial.print(y);   Serial.print("] ");         // shorter version (ID)
+#else
+    #define SPFT2(x,y);  Serial.print(FP(FT_##x)); Serial.print("[");   Serial.print(y);   Serial.print("] ");         // shorter version (ID)
+#endif
+
+FT(title, "\nCompass ang gyro  test\n" );
+FT(compass, "Compass" );
+FT(x, "[X]" );
+FT(y, "[Y]" );
+FT(z, "[Z]" );
+

+ 26 - 0
SE/stuff/P5_Automation_can-dev-res-working-1930/___SUBMODULES___/gyro_and_compass_test/u8g2__setup.h

@@ -0,0 +1,26 @@
+ 
+  u8x8.begin();
+    u8x8.setFlipMode(1);
+  u8x8.setFont(u8x8_font_chroma48medium8_r);
+  
+  u8x8log.begin(u8x8, U8LOG_WIDTH, U8LOG_HEIGHT, u8log_buffer);
+  u8x8log.setRedrawMode(1);		// 0: Update screen with newline, 1: Update screen for every char  
+  
+/*
+ u8g2.begin();
+          u8g2.setDisplayRotation(U8G2_R2);
+
+  u8g2.clearBuffer();					// clear the internal memory
+  u8g2.setFont(u8g2_font_helvR10_tr);	// choose a suitable font
+  u8g2.drawStr(0,12,"UpdateDisplayArea");	// write something to the internal memory
+  
+  // draw a frame, only the content within the frame will be updated
+  // the frame is never drawn again, but will stay on the display
+  u8g2.drawBox(pixel_area_x_pos-1, pixel_area_y_pos-1, pixel_area_width+2, pixel_area_height+2);
+  
+  u8g2.sendBuffer();					// transfer internal memory to the display
+  
+  u8g2.setFont(u8g2_font_courB18_tr);	// set the target font for the text width calculation
+  width = u8g2.getUTF8Width(text);		// calculate the pixel width of the text
+  offset = width+pixel_area_width;
+  */