Show Posts
Pages: 1 [2] 3 4 ... 14
16  Community / Bar Sport / Re: whats with the attitude on: March 12, 2014, 04:00:38 pm
Example of the attitude, I had a problem with dtostrf, and asked for help in the programming forum. Some replies:
----------------------
Code:

Serial.println('   ');

What's that?
----------------------
 and
-----------------------
The argument to Serial.print() should be a double-quoted string when you wish to print a string literal, such as:

Code:

 
Serial.println("I'm here");


The "ln" at the end of Serial.println() means the next thing printed is on a new line. No need for the redundant blank space. Indeed, I'm not sure what the compiler does with the single-quote space.
-------------------------
and
Or, indeed, multiple single-quote spaces.
--------------------------

No one addressed my question, just picked nits with a small trivial error!!!

Jim
17  Using Arduino / Programming Questions / Re: dtostrf question on: March 11, 2014, 04:07:06 pm
Or, indeed, multiple single-quote spaces.
So spank me and send me to bed without dinner. What does this have to do with my question!

Jim
18  Using Arduino / Programming Questions / Re: dtostrf question on: March 11, 2014, 01:49:16 pm
Code:
Serial.println('   ');
What's that?
A blank line separator

Jim
19  Using Arduino / Programming Questions / Re: Arduino <> raspberry pi via i2c on: March 11, 2014, 11:34:07 am
Quote
In the writeData function.
Which wasn't even in the first code you posted. I've lost track of what your problem is.
I trying to pass data from arduino to rpi via i2c.

Jim
20  Using Arduino / Programming Questions / Re: dtostrf question on: March 10, 2014, 04:00:40 pm
We can't do much unless you post your code. Format it first in the IDE (Ctrl-T) and then post it using the code tags (the # icon). However, if I had to bet, my guess is that you set the width parameter to dtostrf() larger than you want.
Code:
/**
 * ReadSHT1xValues
 *
 * Read temperature and humidity values from an SHT1x-series (SHT10,
 * SHT11, SHT15) sensor.
 *
 * Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
 * www.practicalarduino.com
 */

#include <SHT1x.h>
#include <Wire.h>
#include <UTFT.h>\
#include <stdlib.h>



// Specify data and clock connections and instantiate SHT1x object
#define dataPin  15
#define clockPin 14
#define SLAVE_ADDRESS 0x04
extern uint8_t BigFont[];
char tStr[7];
char hStr[4];

UTFT    myGLCD(ITDB32S,38,39,40,41);
SHT1x   sht1x(dataPin, clockPin);


void setup()
{
  Serial.begin(115200); // Open serial connection to report values to host
  Serial.println("Starting up");
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setFont(BigFont);
  myGLCD.setBackColor(0, 0, 255);
  Wire.begin(0x04); // join i2c bus
}

void loop()
{
  float temp_c;
  float temp_f;
  float humidity;

  // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();


  dtostrf(temp_f, 6, 2, tStr);
  dtostrf(humidity, 2, 0, hStr);
  Serial.print(tStr);
  Serial.println('   ');
  Serial.print(hStr);
  Serial.println('   ');
  myGLCD.print("Temperature: ",LEFT,0);
  myGLCD.print(tStr,15*13,0);
  myGLCD.print("Humidity: ",LEFT,15);
  myGLCD.print(hStr,12*13,15);
  delay(2000);
}

// callback for received data
void receiveData()
{
  char c = Wire.read();
///  Serial.println(c);
}



void writeData (char* data)
{
  Wire.beginTransmission(04); // transmit to device #04
  // device address is specified in datasheet
  Wire.write(data);             // sends value byte 
  Wire.endTransmission();     // stop transmitting

  delay(500);
}

// callback for received data
void readData ()
{
  int number;
  while(Wire.available())
  {
    number = Wire.read();
    switch (number)
    {
    case 1:
      writeData(tStr);
      break;
    case  2:
      writeData(hStr);
      break;
    }
  }
}

Relevant part is is loop function

Jim
21  Using Arduino / Programming Questions / dtostrf question on: March 10, 2014, 12:35:45 pm
I wrote this code which should display temperature with 2 digits after the decimal point and humidity with none on both a lcd and serial monitor. It displays correctly as written on the lcd
 71.23
29
the space in front of the 7 is to make room for a - sign, but on the serial monitor you get:
71.2384
298224
I am using the definition of dtostrf given at http://bradsduino.blogspot.com/2013/05/arduino-c-code-to-convert-float-to.html
I can't  understand why the two displays are displaying different.
Jim
22  Using Arduino / Programming Questions / Re: Arduino <> raspberry pi via i2c on: March 10, 2014, 11:48:04 am
Quote
and the general consensus was that the arduino is not passing good info.
Based on what evidence? Where do you (think you) actually send data to the I2C bus?
In the writeData function. It works in arduino code
Code:
#include <Wire.h>

#define SLAVE_ADDRESS 0x04
int number = 0;
int state = 0;

void setup() {
    pinMode(13, OUTPUT);
    Serial.begin(9600);         // start serial for output
    // initialize i2c as slave
    Wire.begin(SLAVE_ADDRESS);

    // define callbacks for i2c communication
    Wire.onReceive(receiveData);
    Wire.onRequest(sendData);

    Serial.println("Ready!");
}

void loop() {
    delay(100);
}

// callback for received data
void receiveData(int byteCount){

    while(Wire.available()) {
        number = Wire.read();
        Serial.print("data received: ");
        Serial.println(number);

        if (number == 1){

            if (state == 0){
                digitalWrite(13, HIGH); // set the LED on
                state = 1;
            }
            else{
                digitalWrite(13, LOW); // set the LED off
                state = 0;
            }
         }
     }
}

// callback for sending data
void sendData(){
    Wire.write(number);
}
pi code
Code:
import smbus
import time
# for RPI version 1, use "bus = smbus.SMBus(0)"
bus = smbus.SMBus(1)

# This is the address we setup in the Arduino Program
address = 0x04

def writeNumber(value):
    bus.write_byte(address, value)
    # bus.write_byte_data(address, 0, value)
    return -1

def readNumber():
    number = bus.read_byte(address)
    # number = bus.read_byte_data(address, 1)
    return number

while True:
    var = input("Enter 1 - 9: ")
    if not var:
        continue

    writeNumber(var)
    print "RPI: Hi Arduino, I sent you ", var
    # sleep one second
    time.sleep(1)

    number = readNumber()
    print "Arduino: Hey RPI, I received a digit ", number
    print


where result on pi is

  RPI: Hi Arduino, I sent you  2

Arduino: Hey RPI, I received a digit   2

  RPI: Hi Arduino, I sent you  9

Arduino: Hey RPI, I received a digit   9
Jim
23  Using Arduino / Programming Questions / Arduino <> raspberry pi via i2c on: March 09, 2014, 08:16:01 pm
I am trying to pass data to a rpi from arduino via i2c.The lcd is displaying the correct values at the arduino. i am getting this result from the rpi
quote]
    Enter Task
    1 Check Time
    2 North Garage Door
    3 South Garage Door
    : 1
    RPI:Hi Arduino, I sent you a 1
    Time is
    []

   Enter Task
    1 Check Time
    2 North Garage Door
    3 South Garage Door
    : 2
    RPI:Hi Arduino, I sent you a 1
    Time is
   
 Enter Task
    1 Check Time
    2 North Garage Door
    3 South Garage Door
    [][/quote]

Arduino code:
Code:
/**
 * ReadSHT1xValues
 *
 * Read temperature and humidity values from an SHT1x-series (SHT10,
 * SHT11, SHT15) sensor.
 *
 * Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
 * www.practicalarduino.com
 */

#include <SHT1x.h>
#include <Wire.h>
#include <UTFT.h>\




// Specify data and clock connections and instantiate SHT1x object
#define dataPin  15
#define clockPin 14
#define SLAVE_ADDRESS 0x04
extern uint8_t BigFont[];
char tStr[7];
char hStr[4];

UTFT    myGLCD(ITDB32S,38,39,40,41);
SHT1x   sht1x(dataPin, clockPin);


void setup()
{
  Serial.begin(115200); // Open serial connection to report values to host
  Serial.println("Starting up");
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setFont(BigFont);
  myGLCD.setBackColor(0, 0, 255);
  Wire.begin(0x04); // join i2c bus
}

void loop()
{
  float temp_c;
  float temp_f;
  float humidity;

  // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();


  dtostrf(temp_f, 4, 1, tStr);
  dtostrf(humidity, 2, 0, hStr);
  Serial.print(tStr);
  Serial.println('   ');
  Serial.print(hStr);
  Serial.println('   ');
  myGLCD.print("Temperature: ",LEFT,0);
  myGLCD.print(tStr,15*13,0);
  myGLCD.print("Humidity: ",LEFT,15);
  myGLCD.print(hStr,12*13,15);
  delay(2000);
}

// callback for received data
void receiveData()
{
  char c = Wire.read();
///  Serial.println(c);
}



void writeData (char* data)
{
  Wire.beginTransmission(04); // transmit to device #04
  // device address is specified in datasheet
  Wire.write(data);             // sends value byte 
  Wire.endTransmission();     // stop transmitting

  delay(500);
}

// callback for received data
void readData ()
{
  int number;
  while(Wire.available())
  {
    number = Wire.read();
    switch (number)
    {
    case 1:
      writeData(tStr);
      break;
    case  2:
      writeData(hStr);
      break;
    }
  }
}

Raspberry pi code
Code:
    import smbus
    import time
    # for RPI version 1, use "bus = smbus.SMBus(0)"
    bus = smbus.SMBus(1)

    # This is the address we setup in the Arduino Program
    address = 0x04

    def writeNumber(address, value):
        bus.write_byte(address, value)
        # bus.write_byte_data(address, value)
        return -1

    def writeChar(address, value):
        bus.write_word(address, value)
        return -1


    def readNumber(address):
        number = bus.read_byte(address)
        #number = bus.read_byte_data(address, 1)
        return number

    while True:
        print "Enter Task"
        print "1  Ckeck Time"
        print "2  North Garage Door"
        print "3  South Garage Door"
        var = input(": ")
        if not var:
            continue

        writeNumber(address, var)
        print "RPI: Hi Arduino, I sent you ", var


        # sleep one second
        time.sleep(1)

        number = readNumber(address)
        print "Arduino: Hey RPI, I received a digit ", number
        print


    def rdb():
        buffer[10]
        bus.read_block_data(address,buffer)
I posted this on the rpi forum and the general consensus was that the arduino is not passing good info. So I'd like your opinion.

Jim
24  Using Arduino / Project Guidance / I2c sniffer on: March 08, 2014, 02:10:13 pm
Is it possible to setup an arduino as a slave on i2c which monitors and displays all traffic on the bus on the serial monitor? It should probably look at the length to decide if it a string,word or byte and process accordingly. Has anyone done this?

Jim
25  Using Arduino / Programming Questions / Re: Trouble with i2c on: March 07, 2014, 03:47:28 pm
Thanks Pete, now I have to chase down logic (me dummy) errors
Jim
26  Using Arduino / Programming Questions / Trouble with i2c on: March 07, 2014, 01:21:43 pm
I have a Raspberry pi connected to an Arduino over i2c. I am attempting to pass a string to the pi.
My code:
Code:
/**
 * ReadSHT1xValues
 *
 * Read temperature and humidity values from an SHT1x-series (SHT10,
 * SHT11, SHT15) sensor.
 *
 * Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
 * www.practicalarduino.com
 */

#include <SHT1x.h>
#include <Wire.h>
#include <UTFT.h>\




// Specify data and clock connections and instantiate SHT1x object
#define dataPin  15
#define clockPin 14
#define SLAVE_ADDRESS 0x04
extern uint8_t BigFont[];
char tStr[7];
char hStr[4];

UTFT    myGLCD(ITDB32S,38,39,40,41);
SHT1x   sht1x(dataPin, clockPin);


void setup()
{
    Serial.begin(38400); // Open serial connection to report values to host
    Serial.println("Starting up");
    myGLCD.InitLCD();
    myGLCD.clrScr();
    myGLCD.setFont(BigFont);
    myGLCD.setBackColor(0, 0, 255);
    Wire.begin(0x04); // join i2c bus
}

void loop()
{
  float temp_c;
  float temp_f;
  float humidity;
 
  // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();


dtostrf(temp_f, 1, 1, tStr);
dtostrf(humidity, 1, 0, hStr);
Serial.print(tStr);
Serial.print(' ');
Serial.print(hStr);
myGLCD.print("Temperature: ",LEFT,0);
myGLCD.print(tStr,15*13,0);
myGLCD.print("Humidity: ",LEFT,15);
myGLCD.print(hStr,12*13,15);
delay(2000);
}

// callback for received data
void receiveData()
{
    char c = Wire.read();
    Serial.println(c);
}



void writeData (char data)
{
  Wire.beginTransmission(04); // transmit to device #04
                              // device address is specified in datasheet
  Wire.write(data);             // sends value byte 
  Wire.endTransmission();     // stop transmitting

  delay(500);
}

// callback for received data
void readData ()
{
    int number;
    while(Wire.available())
    {
number = Wire.read();
         switch (number)
         {
              case 1:
                  writeData(tStr);
                  break;
              case  2:
                  writeData(hStr);
                  break;
         }
    }
}
The error I am getting is:

readTemp_ino1.ino: In function 'void readData()':
readTemp_ino1:94: error: invalid conversion from 'char*' to 'char'
readTemp_ino1:94: error: initializing argument 1 of 'void writeData(char)'
readTemp_ino1:97: error: invalid conversion from 'char*' to 'char'
readTemp_ino1:97: error: initializing argument 1 of 'void writeData(char)'

What am I doing wrong?

Jim
27  Community / Bar Sport / Re: Rain on: March 03, 2014, 09:56:20 pm
Doubt if they were sustained, just gust, but sustained winds were probably in the 60-80 range. at our house they were 40-60, gusting to 80+, blew the roof right off my observatory!

Jim
28  Community / Bar Sport / Re: Rain on: February 28, 2014, 08:38:52 pm
The problem here is wind, the snow we put up with. We have had 2 weeks of high wind. 60-80 mph at home, but the road down to Denver has been closed 10 times with wind of 110 mph.

Jim
29  Using Arduino / Installation & Troubleshooting / Re: Raspberry Pi doesn't see Mega on: February 27, 2014, 01:26:01 pm
Sorry if I sounded irritating, I was confused by the I2C and serial monitor , dumb me smiley

No problem, I just saw that I needed to reduce things.

Are you plugging the Arduino directly to the USB Port in RPi, if yes then try using a powered USB hub(it may happen that the RPi cannot provide sufficient power to the Arduino through USB).

I am connected to the rpi through a powered USB 3.0/2.0 hub.

If it didn't worked try booting RPi with Arduino connected.

Good suggestion, but no joy, the Tools>Serial Port menu item is still grayed out
If that too didn't work,sorry I don't have anymore ideas. I don't have Arduino and ,I only have a Arduino on beadboard with CP2102 for USB TTL conversion and it seems RPi detects it and I am perfectly ok with using arduino with RPi.(Since RPi uses a linux distribution it must detect FTDI/atmega too , I don't know).

I am now connecting a 20x4 lcd via the i2c bus to use as a serial monitor. I move the arduino over to the PC for programming and downloading. Still, a lot of hassle becuase of missing serial port! Where are the gurus?
30  Using Arduino / Installation & Troubleshooting / Re: Raspberry Pi doesn't see Mega on: February 26, 2014, 04:35:26 pm
Quote
The USB  input on the Arduino is connected to a USB port on the pI through a powered USB Hub.
I have found that using this method the Arduino can appear at one of two com port addresses at random.
In python I cope with this as so:-
Code:
import serial
try:
   ser = serial.Serial('/dev/ttyACM0',115200, timeout=2)
except :
   ser = serial.Serial('/dev/ttyACM1',115200, timeout=2)   

I don't understand why everyone is so fixated on what I doing. Think of it this way, i loaded the Arduino software, plugged in the Mega, and there is no listings in "Tools>Serial Port". so I cannot even download code, much less use the serial monitor to monitor  what the Arduino is doing! The i2c is working fine, the blacklist is correct! I can blink the port 13 led from the pi just fine!

Jim
Pages: 1 [2] 3 4 ... 14