From 6d31a53b351218a96d5e9375c4a1017e1e3c8faf Mon Sep 17 00:00:00 2001 From: LinoSchmidt Date: Tue, 28 Sep 2021 21:44:44 +0200 Subject: [PATCH] copied old files into repository --- .gitignore | 5 + .vscode/extensions.json | 7 + .vscode/settings.json | 3 + BMP085test/BMP085test.ino | 66 +++++++++ include/README | 39 ++++++ include/sensorapi/sensorapi.pde | 132 ++++++++++++++++++ lib/README | 46 ++++++ .../i2c_address_detect/i2c_address_detect.ino | 21 +++ lib/examples/spi_modetest/spi_modetest.ino | 29 ++++ lib/examples/spi_registers/spi_registers.ino | 34 +++++ platformio.ini | 15 ++ src/main.cpp | 86 ++++++++++++ src/test.py | 4 + test/README | 11 ++ 14 files changed, 498 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 BMP085test/BMP085test.ino create mode 100644 include/README create mode 100644 include/sensorapi/sensorapi.pde create mode 100644 lib/README create mode 100644 lib/examples/i2c_address_detect/i2c_address_detect.ino create mode 100644 lib/examples/spi_modetest/spi_modetest.ino create mode 100644 lib/examples/spi_registers/spi_registers.ino create mode 100644 platformio.ini create mode 100644 src/main.cpp create mode 100644 src/test.py create mode 100644 test/README diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..e80666b --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0db5873 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cmake.configureOnOpen": true +} \ No newline at end of file diff --git a/BMP085test/BMP085test.ino b/BMP085test/BMP085test.ino new file mode 100644 index 0000000..308fa30 --- /dev/null +++ b/BMP085test/BMP085test.ino @@ -0,0 +1,66 @@ +#include +#include + +/*************************************************** + This is an example for the BMP085 Barometric Pressure & Temp Sensor + + Designed specifically to work with the Adafruit BMP085 Breakout + ----> https://www.adafruit.com/products/391 + + These displays use I2C to communicate, 2 pins are required to + interface + Adafruit invests time and resources providing this open source code, + please support Adafruit and open-source hardware by purchasing + products from Adafruit! + + Written by Limor Fried/Ladyada for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ****************************************************/ + +// Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!) +// Connect GND to Ground +// Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5 +// Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4 +// EOC is not used, it signifies an end of conversion +// XCLR is a reset pin, also not used here + +Adafruit_BMP085 bmp; + +void setup() { + Serial.begin(9600); + if (!bmp.begin()) { + Serial.println("Could not find a valid BMP085 sensor, check wiring!"); + while (1) {} + } +} + +void loop() { + Serial.print("Temperature = "); + Serial.print(bmp.readTemperature()); + Serial.println(" *C"); + + Serial.print("Pressure = "); + Serial.print(bmp.readPressure()); + Serial.println(" Pa"); + + // Calculate altitude assuming 'standard' barometric + // pressure of 1013.25 millibar = 101325 Pascal + Serial.print("Altitude = "); + Serial.print(bmp.readAltitude()); + Serial.println(" meters"); + + Serial.print("Pressure at sealevel (calculated) = "); + Serial.print(bmp.readSealevelPressure()); + Serial.println(" Pa"); + + // you can get a more precise measurement of altitude + // if you know the current sea level pressure which will + // vary with weather and such. If it is 1015 millibars + // that is equal to 101500 Pascals. + Serial.print("Real altitude = "); + Serial.print(bmp.readAltitude(101500)); + Serial.println(" meters"); + + Serial.println(); + delay(500); +} \ No newline at end of file diff --git a/include/README b/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/include/sensorapi/sensorapi.pde b/include/sensorapi/sensorapi.pde new file mode 100644 index 0000000..46b7b51 --- /dev/null +++ b/include/sensorapi/sensorapi.pde @@ -0,0 +1,132 @@ +#include +#include +#include + +/* This driver uses the Adafruit unified sensor library (Adafruit_Sensor), + which provides a common 'type' for sensor data and some helper functions. + + To use this driver you will also need to download the Adafruit_Sensor + library and include it in your libraries folder. + + You should also assign a unique ID to this sensor for use with + the Adafruit Sensor API so that you can identify this particular + sensor in any data logs, etc. To assign a unique ID, simply + provide an appropriate value in the constructor below (12345 + is used by default in this example). + + Connections + =========== + Connect SCL to analog 5 + Connect SDA to analog 4 + Connect VDD to 3.3V DC + Connect GROUND to common ground + + History + ======= + 2013/JUN/17 - Updated altitude calculations (KTOWN) + 2013/FEB/13 - First version (KTOWN) +*/ + +Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085); + +/**************************************************************************/ +/* + Displays some basic information on this sensor from the unified + sensor API sensor_t type (see Adafruit_Sensor for more information) +*/ +/**************************************************************************/ +void displaySensorDetails(void) +{ + sensor_t sensor; + bmp.getSensor(&sensor); + Serial.println("------------------------------------"); + Serial.print ("Sensor: "); Serial.println(sensor.name); + Serial.print ("Driver Ver: "); Serial.println(sensor.version); + Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id); + Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" hPa"); + Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" hPa"); + Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" hPa"); + Serial.println("------------------------------------"); + Serial.println(""); + delay(500); +} + +/**************************************************************************/ +/* + Arduino setup function (automatically called at startup) +*/ +/**************************************************************************/ +void setup(void) +{ + Serial.begin(9600); + Serial.println("Pressure Sensor Test"); Serial.println(""); + + /* Initialise the sensor */ + if(!bmp.begin()) + { + /* There was a problem detecting the BMP085 ... check your connections */ + Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!"); + while(1); + } + + /* Display some basic information on this sensor */ + displaySensorDetails(); +} + +/**************************************************************************/ +/* + Arduino loop function, called once 'setup' is complete (your own code + should go here) +*/ +/**************************************************************************/ +void loop(void) +{ + /* Get a new sensor event */ + sensors_event_t event; + bmp.getEvent(&event); + + /* Display the results (barometric pressure is measure in hPa) */ + if (event.pressure) + { + /* Display atmospheric pressue in hPa */ + Serial.print("Pressure: "); + Serial.print(event.pressure); + Serial.println(" hPa"); + + /* Calculating altitude with reasonable accuracy requires pressure * + * sea level pressure for your position at the moment the data is * + * converted, as well as the ambient temperature in degress * + * celcius. If you don't have these values, a 'generic' value of * + * 1013.25 hPa can be used (defined as SENSORS_PRESSURE_SEALEVELHPA * + * in sensors.h), but this isn't ideal and will give variable * + * results from one day to the next. * + * * + * You can usually find the current SLP value by looking at weather * + * websites or from environmental information centers near any major * + * airport. * + * * + * For example, for Paris, France you can check the current mean * + * pressure and sea level at: http://bit.ly/16Au8ol */ + + /* First we get the current temperature from the BMP085 */ + float temperature; + bmp.getTemperature(&temperature); + Serial.print("Temperature: "); + Serial.print(temperature); + Serial.println(" C"); + + /* Then convert the atmospheric pressure, and SLP to altitude */ + /* Update this next line with the current SLP for better results */ + float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; + Serial.print("Altitude: "); + Serial.print(bmp.pressureToAltitude(seaLevelPressure, + event.pressure)); + Serial.println(" m"); + Serial.println(""); + } + else + { + Serial.println("Sensor error"); + } + delay(1000); +} diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/lib/examples/i2c_address_detect/i2c_address_detect.ino b/lib/examples/i2c_address_detect/i2c_address_detect.ino new file mode 100644 index 0000000..b150525 --- /dev/null +++ b/lib/examples/i2c_address_detect/i2c_address_detect.ino @@ -0,0 +1,21 @@ +#include + +Adafruit_I2CDevice i2c_dev = Adafruit_I2CDevice(0x10); + +void setup() { + while (!Serial) { delay(10); } + Serial.begin(115200); + Serial.println("I2C address detection test"); + + if (!i2c_dev.begin()) { + Serial.print("Did not find device at 0x"); + Serial.println(i2c_dev.address(), HEX); + while (1); + } + Serial.print("Device found on address 0x"); + Serial.println(i2c_dev.address(), HEX); +} + +void loop() { + +} diff --git a/lib/examples/spi_modetest/spi_modetest.ino b/lib/examples/spi_modetest/spi_modetest.ino new file mode 100644 index 0000000..10168c5 --- /dev/null +++ b/lib/examples/spi_modetest/spi_modetest.ino @@ -0,0 +1,29 @@ +#include + +#define SPIDEVICE_CS 10 +Adafruit_SPIDevice spi_dev = Adafruit_SPIDevice(SPIDEVICE_CS, 100000, SPI_BITORDER_MSBFIRST, SPI_MODE1); +//Adafruit_SPIDevice spi_dev = Adafruit_SPIDevice(SPIDEVICE_CS, 13, 12, 11, 100000, SPI_BITORDER_MSBFIRST, SPI_MODE1); + + +void setup() { + while (!Serial) { delay(10); } + Serial.begin(115200); + Serial.println("SPI device mode test"); + + if (!spi_dev.begin()) { + Serial.println("Could not initialize SPI device"); + while (1); + } +} + +void loop() { + Serial.println("\n\nTransfer test"); + for (uint16_t x=0; x<=0xFF; x++) { + uint8_t i = x; + Serial.print("0x"); Serial.print(i, HEX); + spi_dev.read(&i, 1, i); + Serial.print("/"); Serial.print(i, HEX); + Serial.print(", "); + delay(25); + } +} \ No newline at end of file diff --git a/lib/examples/spi_registers/spi_registers.ino b/lib/examples/spi_registers/spi_registers.ino new file mode 100644 index 0000000..e24f1aa --- /dev/null +++ b/lib/examples/spi_registers/spi_registers.ino @@ -0,0 +1,34 @@ +#include +#include + +#define SPIDEVICE_CS 10 +Adafruit_SPIDevice spi_dev = Adafruit_SPIDevice(SPIDEVICE_CS); + +void setup() { + while (!Serial) { delay(10); } + Serial.begin(115200); + Serial.println("SPI device register test"); + + if (!spi_dev.begin()) { + Serial.println("Could not initialize SPI device"); + while (1); + } + + Adafruit_BusIO_Register id_reg = Adafruit_BusIO_Register(&spi_dev, 0x0F, ADDRBIT8_HIGH_TOREAD); + uint8_t id; + id_reg.read(&id); + Serial.print("ID register = 0x"); Serial.println(id, HEX); + + Adafruit_BusIO_Register thresh_reg = Adafruit_BusIO_Register(&spi_dev, 0x0C, ADDRBIT8_HIGH_TOREAD, 2, LSBFIRST); + uint16_t thresh; + thresh_reg.read(&thresh); + Serial.print("Initial threshold register = 0x"); Serial.println(thresh, HEX); + + thresh_reg.write(~thresh); + + Serial.print("Post threshold register = 0x"); Serial.println(thresh_reg.read(), HEX); +} + +void loop() { + +} \ No newline at end of file diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..d32cd90 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,15 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:leonardo] +platform = atmelavr +board = leonardo +framework = arduino +lib_deps = arduino-libraries/Servo @ ^1.1.8 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..bad3d7c --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,86 @@ +#include +#include + +#define servoDrehungPin 10 +#define servoArmPin 7 +#define servoOberarmPin 8 +#define servoHandPin 9 +#define poti1Pin 0 +#define poti2Pin 5 +#define poti3Pin 2 +#define poti4Pin 3 +#define loopTime 25 +#define PotiFehlerBereich 100 +#define AusschaltDelay 80 + +Servo servoDrehung, servoArm, servoOberarm, servoHand; + +int Poti1, Poti2, Poti3, Poti4; +int servoDrehungPos, servoArmPos, servoOberarmPos, servoHandPos; +int servoDrehungPosOLD, servoArmPosOLD, servoOberarmPosOLD, servoHandPosOLD; +int offtime; + +bool disabled = false; + +void setup(){ + servoDrehung.attach(servoDrehungPin); + servoArm.attach(servoArmPin); + servoOberarm.attach(servoOberarmPin); + servoHand.attach(servoHandPin); + + Serial.begin(9600); +} + +void loop(){ + Poti1 = analogRead(poti1Pin); + Poti2 = analogRead(poti2Pin); + Poti3 = analogRead(poti3Pin); + Poti4 = analogRead(poti4Pin); + + servoDrehungPos = map(Poti1, 0, 1023, 0, 180); + servoArmPos = map(Poti2, 1023, 0, 0, 130); + servoOberarmPos = map(Poti3, 0, 1023, 0, 180); + servoHandPos = map(Poti4, 0, 1023, 45, 140); + + if(servoDrehungPos <= servoDrehungPosOLD + PotiFehlerBereich && servoDrehungPos >= servoDrehungPosOLD - PotiFehlerBereich && servoArmPos <= servoArmPosOLD + PotiFehlerBereich && servoArmPos >= servoArmPosOLD - PotiFehlerBereich && servoOberarmPos <= servoOberarmPosOLD + PotiFehlerBereich && servoOberarmPos >= servoOberarmPosOLD - PotiFehlerBereich && servoHandPos <= servoHandPosOLD + PotiFehlerBereich && servoHandPos >= servoHandPosOLD - PotiFehlerBereich){ + if(offtime < AusschaltDelay){ + offtime++; + } + } + else{ + offtime = 0; + + servoDrehungPosOLD = servoDrehungPos; + servoArmPosOLD = servoArmPos; + servoOberarmPosOLD = servoOberarmPos; + servoHandPosOLD = servoHandPos; + } + + if(offtime >= AusschaltDelay){ + servoDrehung.detach(); + servoArm.detach(); + servoOberarm.detach(); + servoHand.detach(); + + disabled = true; + } + else{ + if (disabled){ + servoDrehung.attach(servoDrehungPin); + servoArm.attach(servoArmPin); + servoOberarm.attach(servoOberarmPin); + servoHand.attach(servoHandPin); + + disabled = false; + } + + servoDrehung.write(servoDrehungPos); + servoArm.write(servoArmPos); + servoOberarm.write(servoOberarmPos); + servoHand.write(servoHandPos); + } + + Serial.println(String(offtime) + "," + String(servoDrehungPos) + "," + String(servoArmPos) + "," + String(servoOberarmPos) + "," + String(servoHandPos)); + + delay(loopTime); +} \ No newline at end of file diff --git a/src/test.py b/src/test.py new file mode 100644 index 0000000..f461564 --- /dev/null +++ b/src/test.py @@ -0,0 +1,4 @@ +hallo = input("Zahl1:") +b = input("Zahl2:") + +print(hallo+b) \ No newline at end of file diff --git a/test/README b/test/README new file mode 100644 index 0000000..b94d089 --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html