Ich benutze ELDK 5.5 als Entwicklungsumgebung für Programme auf dem Elektor-Linux-Board (unter Ubuntu).
Viele Grüße
RoKo66
/*
* ads1115Test.cpp
*
* Created on: Nov 2, 2014
* Author: elektor
*/
#include "gnublin.h"
// Include the bit-banged I2C driver.
#include "soft_i2c.h"
// Include the driver definition file.
#include "ads1x1x.h"
// Create an ADC object.
ADS1x1x_config_t my_adc;
gnublin_gpio sda_pin;
gnublin_gpio scl_pin;
void soft_i2c_delay(void)
{
sleep(5);
}
void soft_i2c_sda_mode(uint8_t value)
{
if (value==0) sda_pin.pinMode(01,INPUT); // use pull-ups on bus
else sda_pin.pinMode(01,OUTPUT);
}
void soft_i2c_sda_write(uint8_t value)
{
sda_pin.digitalWrite(01,value);
}
uint8_t soft_i2c_sda_read(void)
{
return sda_pin.digitalRead(01);
}
void soft_i2c_scl_write(uint8_t value)
{
scl_pin.digitalWrite(02,value);
}
// uint8_t ADS1x1x_i2c_start_write(uint8_t i2c_address)
// {
// return soft_i2c_start_write(i2c_address);
// }
// uint8_t ADS1x1x_i2c_write(uint8_t x)
// {
// return soft_i2c_write(x);
// }
// uint8_t ADS1x1x_i2c_start_read(uint8_t i2c_address, uint16_t bytes_to_read)
// {
// return soft_i2c_start_read(i2c_address,bytes_to_read);
// }
// uint8_t ADS1x1x_i2c_read(void)
// {
// return soft_i2c_read();
// }
// uint8_t ADS1x1x_i2c_stop(void)
// {
// soft_i2c_stop();
// return 0;
// }
// void setup(void)
// {
// Serial.begin(115200);
// Serial.println("13048 ADS1115 ADC borad");
// Serial.println("(c) Elektor, 29/04/2014");
// Serial.println("");
//
// sda_pin.pinMode(01,OUTPUT);
// scl_pin.pinMode(02,OUTPUT);
// if (ADS1x1x_init(&my_adc, ADS1115, ADS1x1x_I2C_ADDRESS_ADDR_TO_GND, MUX_SINGLE_0, PGA_2048)==0)
// {
// Serial.println("Could not initialize ADC structure.");
// }
// }
int main(void)
{
// Loop over all possible input combinations.
for (unsigned int input=0; input<0x8000; input+=0x1000)
{
// ADS1x1x_set_multiplexer(&my_adc,(ADS1x1x_mux_t)input);
// ADS1x1x_start_conversion(&my_adc);
// Default sample rate is 128 samples/s i.e. one sample every 7.8 ms.
sleep(8);
// Display result as voltage (remember, the PGA was set to 2.048 V)
//Serial.println(ADS1x1x_read(&my_adc)*2.048/32767.0);
}
// Serial.println("---");
sleep(500);
}
/*
* ads1115Test.cpp
*
* Created on: Nov 2, 2014
* Author: elektor
*/
#include "gnublin.h"
// Include the bit-banged I2C driver.
#include "soft_i2c.h"
// Include the driver definition file.
#include "ads1x1x.h"
// Create an ADC object.
ADS1x1x_config_t my_adc;
gnublin_gpio sda_pin;
gnublin_gpio scl_pin;
void soft_i2c_delay(void)
{
sleep(0.005);
}
void soft_i2c_sda_mode(uint8_t value)
{
if (value==0) sda_pin.pinMode(10,INPUT); // use pull-ups on bus
else sda_pin.pinMode(00,OUTPUT);
}
void soft_i2c_sda_write(uint8_t value)
{
sda_pin.digitalWrite(00,value);
}
uint8_t soft_i2c_sda_read(void)
{
return sda_pin.digitalRead(00);
}
void soft_i2c_scl_write(uint8_t value)
{
scl_pin.digitalWrite(02,value);
}
uint8_t ADS1x1x_i2c_start_write(uint8_t i2c_address)
{
return soft_i2c_start_write(i2c_address);
}
uint8_t ADS1x1x_i2c_write(uint8_t x)
{
return soft_i2c_write(x);
}
uint8_t ADS1x1x_i2c_start_read(uint8_t i2c_address, uint16_t bytes_to_read)
{
return soft_i2c_start_read(i2c_address,bytes_to_read);
}
uint8_t ADS1x1x_i2c_read(void)
{
return soft_i2c_read();
}
uint8_t ADS1x1x_i2c_stop(void)
{
soft_i2c_stop();
return 0;
}
void setup(void)
{
// Serial.begin(115200);
// Serial.println("13048 ADS1115 ADC borad");
// Serial.println("(c) Elektor, 29/04/2014");
// Serial.println("");
//
sda_pin.pinMode(00,OUTPUT);
scl_pin.pinMode(02,OUTPUT);
if (ADS1x1x_init(&my_adc, ADS1115, ADS1x1x_I2C_ADDRESS_ADDR_TO_GND, MUX_SINGLE_0, PGA_2048)==0)
{
// Serial.println("Could not initialize ADC structure.");
}
}
int main(void)
{
// Loop over all possible input combinations.
for (unsigned int input=0; input<0x8000; input+=0x1000)
{
ADS1x1x_set_multiplexer(&my_adc,(ADS1x1x_mux_t)input);
ADS1x1x_start_conversion(&my_adc);
// Default sample rate is 128 samples/s i.e. one sample every 7.8 ms.
sleep(0.008);
// Display result as voltage (remember, the PGA was set to 2.048 V)
//Serial.println(ADS1x1x_read(&my_adc)*2.048/32767.0);
}
// Serial.println("---");
sleep(0.5);
}
/*
* ads1115Test.cpp
*
* Created on: Nov 2, 2014
* Author: elektor
*/
#include "gnublin.h"
#include <iostream>
// Include the bit-banged I2C driver.
#include "soft_i2c.h"
// Include the driver definition file.
#include "ads1x1x.h"
// Create an ADC object.
ADS1x1x_config_t my_adc;
gnublin_gpio sda_pin;
gnublin_gpio scl_pin;
void soft_i2c_delay(void)
{
usleep(5);
}
void soft_i2c_sda_mode(uint8_t value)
{
if (value==0) sda_pin.pinMode(15,INPUT); // use pull-ups on bus
else sda_pin.pinMode(15,OUTPUT);
}
void soft_i2c_sda_write(uint8_t value)
{
sda_pin.digitalWrite(15,value);
}
uint8_t soft_i2c_sda_read(void)
{
return sda_pin.digitalRead(15);
}
void soft_i2c_scl_write(uint8_t value)
{
scl_pin.digitalWrite(11,value);
}
uint8_t ADS1x1x_i2c_start_write(uint8_t i2c_address)
{
return soft_i2c_start_write(i2c_address);
}
uint8_t ADS1x1x_i2c_write(uint8_t x)
{
return soft_i2c_write(x);
}
uint8_t ADS1x1x_i2c_start_read(uint8_t i2c_address, uint16_t bytes_to_read)
{
return soft_i2c_start_read(i2c_address,bytes_to_read);
}
uint8_t ADS1x1x_i2c_read(void)
{
return soft_i2c_read();
}
uint8_t ADS1x1x_i2c_stop(void)
{
soft_i2c_stop();
return 0;
}
void setup(void)
{
// Serial.begin(115200);
// Serial.println("13048 ADS1115 ADC board");
// printf("13048 ADS1115 ADC board");
cout << "13048 ADS1115 ADC board" << endl;
// Serial.println("(c) Elektor, 29/04/2014");
cout << "(c) Elektor, 29/04/2014" << endl;
// Serial.println("");
//
sda_pin.pinMode(15,OUTPUT);
scl_pin.pinMode(11,OUTPUT);
if (ADS1x1x_init(&my_adc, ADS1115, ADS1x1x_I2C_ADDRESS_ADDR_TO_GND, MUX_SINGLE_0, PGA_2048)==0)
{
// Serial.println("Could not initialize ADC structure.");
cout << "Could not initialize ADC structure" << endl;
}
}
int main(void)
{
setup();
unsigned int i = 1;
while (i <= 3)
{
// Loop over all possible input combinations.
for (unsigned int input=0; input<0x8000; input+=0x1000)
{
ADS1x1x_set_multiplexer(&my_adc,(ADS1x1x_mux_t)input);
ADS1x1x_start_conversion(&my_adc);
// Default sample rate is 128 samples/s i.e. one sample every 7.8 ms.
usleep(7813);
// Display result as voltage (remember, the PGA was set to 2.048 V)
//Serial.println(ADS1x1x_read(&my_adc)*2.048/32767.0);
//printf(ADS1x1x_read(&my_adc)*2.048/32767.0);
//printf("some value");
cout << ADS1x1x_read(&my_adc)*2.048/32767.0 << endl;
}
// Serial.println("---");
cout << "---" << endl;
usleep(500000);
i++;
}
}
/
Last login: Sat Nov 8 19:28:58 2014 from elektor-virtualbox.fritz.box
root@gnublin:~# ./ADS1115
13048 ADS1115 ADC board
-0.0367511
-0.0390637
-0.0390637
1.02397
-0.195568
1.02397
1.02397
1.02397
---
-0.0368136
-0.0355636
1.02397
1.02397
-0.197131
1.02397
1.02397
1.02397
---
-0.0388137
-0.0390637
1.02397
1.02397
-0.196443
2.048
1.02397
1.02397
---
root@gnublin:
Return to Elektor-Mikrocontroller-Forum
Users browsing this forum: No registered users and 0 guests