Show Posts
Pages: [1] 2
1  Products / Arduino Yún / Re: Yún, PHP and SQLite on: September 18, 2014, 04:16:24 pm
Hi again

I found some other samplecode starting like this:

Code:
<?php
   
class MyDB extends SQLite3
   
{
      function 
__construct()
      {
         
$this->open('data.db');
      }
   }

And this is working. Maybe the other code used sqlite2 in a faulty way. I do not know. But finding this solution using sqlite3 in an object oriented way, I'm happy as it is. Now I can continue my project development.

This is where I found the solution: http://www.tutorialspoint.com/sqlite/sqlite_php.htm

2  Products / Arduino Yún / Re: Yún, PHP and SQLite on: September 18, 2014, 12:13:47 pm
This is the working Python script:

Code:
import sched, time, sys, datetime
import sqlite3 as lite
sys.path.insert(0, '/usr/lib/python2.7/bridge/')
from bridgeclient import BridgeClient as bridgeclient
s = sched.scheduler(time.time, time.sleep)
value = bridgeclient()                                                     
con = None
con = lite.connect('/mnt/sda1/www/data.db')
cur = con.cursor()
   
def do_something(sc):
    sc.enter(300, 1, do_something, (sc,))
    t = value.get('TEMP')
    k = unicode(datetime.datetime.now())
    cur.execute("INSERT INTO tblTempHist VALUES('" + k + "'," + t + ");")
    con.commit()
    print k + " : " + t
    print "INSERT INTO tblTempHist VALUES('" + k + "'," + t + ");"
   
s.enter(1, 1, do_something, (s,))
s.run()
3  Products / Arduino Yún / Yún, PHP and SQLite on: September 18, 2014, 11:03:33 am
Hi everybody
I installed PHP and SQLite on my Yún. I made a Python script that reads a temperature via bridge each 5 minuttes. It saves the data in a SQLite database. The Python script works as intented.
In PHP, this scripte works:
Code:
<?php
echo sqlite_libversion();
?>
I got version number 2.8.17
But this one result in <h1>Bad Gateway</h1>The process did not produce any response
Code:
<?php
if ($db sqlite_open('/mnt/sda1/www/data.db'0666$error)) {
$result sqlite_query($db"SELECT * FROM tblTempHist");
$rows sqlite_num_rows($result);
echo "Number of rows: $rows";
} else {
die($error);
}
?>

At the beginning I could not get anything but the error. Even with the libversion script. I then installed libsqlite2 and php5-mod-sqlite. I have enablet things in PHP.INI without success.

Any suggestions on where to look for this bug?
4  Using Arduino / LEDs and Multiplexing / Re: TLC5940 - using ATTINY85 to control GSCLK and BLANK on: December 10, 2013, 10:29:07 am
I see Fungus. I missed that part. Thanks.

Well - then I could use the extra free pins on ATTINY85. So the latch goes from Arduino to ATTINY85 and from there to TLC5940 when ATTINY85 is at the end of the grayscale cycle.
5  Using Arduino / LEDs and Multiplexing / TLC5940 - using ATTINY85 to control GSCLK and BLANK on: December 10, 2013, 07:46:36 am
Hi there

I’m using TLC5940 to control LED’s and Servos. I made the GSCLK signal by a 555-circuit to reduce the use of Arduino pins. But it is not precise and I also would like to reduce the number of discrete components. I have a bunch of ATTINY85 lying around.

My idea is to make ATTINY85 control GSCLK and BLANK. Not connected to the Arduino but just contantly providing GSCLK and BLANK signals.
Arduine should then program TLC5940 by using XLAT, SIN and SCLK.
My question is. Are there any dependencies between XLAT on one hand and GSCLK and BLANK on the other? In other words, should the timing of the lathing take into account how far the counter of GSCLK is in its sequence?
Is it a possible solution?

Thanks
6  International / Scandinavia / Re: Dansk arduino webshop-Eksistere interessen? on: April 19, 2013, 07:53:02 am
Nu skal man jo aldrig sige aldrig.
Men der er jo allerede en række danske forhandlere.
I lighed med andre benytter jeg e-bay til mange af de dele jeg bruger og ellers dk.rs-online.com til komponenter.
Et krav er at du kan konkurere på prisen.
Mvh Allan
7  Using Arduino / Networking, Protocols, and Devices / Re: Sending negative numbers from i2c slave via TinyWire on: April 16, 2013, 02:28:21 pm
TinyWire only can only send one byte per request as seen here.https://raw.github.com/Bohdan-Anderson/HeartRateMonitor-ATtiny-I2C/master/i2c_difference/i2c_difference.ino.
 
But you are right about errors in my requestEvent. So I corrected the code and now it is working. Yippee  smiley-grin  smiley-grin  smiley-grin
So here's a good example (full code) for other beginners like me.
Slave code:
Code:
#include "TinyWireS.h"                  // wrapper class for I2C slave routines
#include "PinChangeInterrupt.h"
#define I2C_SLAVE_ADDR  0x26            // i2c slave address (38)

int pin = 3; //LED indicating raising and falling edges in both encoder channels
int chA = 4;//Encoder channel A
int chB = 1;//Encoder channel B
volatile int state = HIGH;
volatile int a=0;
volatile int b=0;
volatile int t=0;
boolean changed = true;
boolean firstbyte = true;
byte lowByte;
byte highByte;

void setup()
{
  pinMode(pin, OUTPUT);
  pinMode(chA, INPUT);
  pinMode(chB, INPUT);
  TinyWireS.begin(I2C_SLAVE_ADDR);      // init I2C Slave mode
  TinyWireS.onRequest(requestEvent);
  attachPcInterrupt(chA, tickA, CHANGE);
  attachPcInterrupt(chB, tickB, CHANGE);
}

void loop()
{
  digitalWrite(pin, state);
}

void requestEvent()
{
  if(firstbyte == true){     // on the first byte we do the math
    lowByte = (byte) (t & 0xff);
    highByte = (byte) ((t >> 8) & 0xff);
    t=0;
    firstbyte = false;      //so next time though we send the next byte    
    TinyWireS.send(lowByte);
  }
  else {
    TinyWireS.send(highByte);
    firstbyte = true;
  }
}

void tickA()
{
  a=digitalRead(chA);
  if (a==b) {
    t=t+1;
  }
  else {
    t=t-1;
  }
  state = !state;
}

void tickB()
{
  b=digitalRead(chB);
  if (a!=b) {
    t=t+1;
  }
  else {
    t=t-1;
  }
  state = !state;
}

And the code on the Master (Arduino):
Code:
#include <Wire.h>
#define I2C_SLAVE_ADDR  0x26
volatile boolean haveData = false;
volatile int value =0;

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}

void loop()
{
  byte hb;
  byte lb;
  Wire.requestFrom(I2C_SLAVE_ADDR,1);
  if (Wire.available()) {
    //    hb=Wire.read();
    lb=Wire.read();
  }
  Wire.requestFrom(I2C_SLAVE_ADDR,1);
  if (Wire.available()) {
    hb=Wire.read();
  }
  value =  ((hb<<8)+lb);
  Serial.print(lb);
  Serial.print(", ");
  Serial.print(hb);
  Serial.print(", ");
  Serial.println (value);
  delay(1500);
}

I wish I would have found an example like this two days ago. Now I hope other can use it in their projects.
Thank you pylon for leading my attention in the right direction.
8  Using Arduino / Networking, Protocols, and Devices / Re: Sending negative numbers from i2c slave via TinyWire on: April 16, 2013, 01:31:39 pm
Hi pylon
The pull-ups are 4.7K.
I think it has to do with converting between integer and bytes. I have rewriten the requestEvent again:

Code:
void requestEvent()
{
  byte lowByte = (byte) (t & 0xff);
  byte highByte = (byte) ((t >> 8) & 0xff);
  if(firstbyte == true){     // on the first byte we do the math
    t=0;
    firstbyte = false;      //so next time though we send the next byte   
    TinyWireS.send(lowByte);
  }
  else {
    TinyWireS.send(highByte);
    firstbyte = true;
    changed = false; 
  }
}
Now the ATtiny85 continue to read the encoder and send data.

Its only the lowByte that contains a value when recieved by the master.
Master loop now contains:
Code:
  byte hb;
  byte lb;
  Wire.requestFrom(I2C_SLAVE_ADDR,1);
  if (Wire.available()) {
    lb=Wire.read();
  }
  Wire.requestFrom(I2C_SLAVE_ADDR,1);
  if (Wire.available()) {
    hb=Wire.read();
  }

hb alwways contain 0. Only lb has a value.
When encoder readings on slave are negative they are near 256. I can find the right value by subtracting 256 from lb value if lb is higher than 126.

So it's me not mastering converting from integer to bytes and back again.
My problem is not yet solved but reduced to binary arithmetic that I don’t fully understand yet.

9  Using Arduino / Networking, Protocols, and Devices / Re: Sending negative numbers from i2c slave via TinyWire on: April 16, 2013, 11:53:14 am
Ok I see. Thanks Borland.
I changed the requestEvent code to this to send two individual bytes:
Code:
void requestEvent()

  byte lowByte = (byte) (t & 0xff);
  byte highByte = (byte) ((t >> 8) & 0xff);
  t=0;
  TinyWireS.send(lowByte);
  TinyWireS.send(highByte);
}

The slave stops working after a few requests.

The master code loop now contains:

Code:
  byte hb;
  byte lb;
  Wire.requestFrom(I2C_SLAVE_ADDR,2);
  if (Wire.available()) {
    lb=Wire.read();
    hb=Wire.read();
  }

Master receives values only a couple of times and the slave stop reading the encoder.

It may well be that the solution is simple, but I can't figure it out. I hope one of you clever people can.
10  Using Arduino / Networking, Protocols, and Devices / Sending negative numbers from i2c slave via TinyWire - SOLVED! on: April 15, 2013, 03:11:31 pm
Hi
I finaly made my ATTiny85 talk with my Arduino Uno. Only strange thing is that small negative integers like 2 become something like 253 when received by the master.

How do I send and receive a negative integer?

My slave read a wheel encoder. My master request current count when needed.
This is the code on the slave
Code:
#include "TinyWireS.h"                  // wrapper class for I2C slave routines
#include "PinChangeInterrupt.h"
#define I2C_SLAVE_ADDR  0x26            // i2c slave address (38)

int pin = 3;
int chA = 4;//pin 3
int chB = 1;//pin 2
volatile int state = HIGH;
volatile int a=0;
volatile int b=0;
volatile int t=0;

void setup()
{
  pinMode(pin, OUTPUT);
  pinMode(chA, INPUT);
  pinMode(chB, INPUT);
  TinyWireS.begin(I2C_SLAVE_ADDR);      // init I2C Slave mode
  TinyWireS.onRequest(requestEvent);
  attachPcInterrupt(chA, tickA, CHANGE);
  attachPcInterrupt(chB, tickB, CHANGE);
}

void loop()
{
  digitalWrite(pin, state);
}

void requestEvent()
{  
    TinyWireS.send(t);
    t=0;
}

void tickA()
{
  a=digitalRead(chA);
  if (a==b) {
    t=t+1;
  }
  else {
    t=t-1;
  }
  state = !state;
}

void tickB()
{
  b=digitalRead(chB);
  if (a!=b) {
    t=t+1;
  }
  else {
    t=t-1;
  }
  state = !state;
}
This is the code on the master
Code:
#include <Wire.h>
#define I2C_SLAVE_ADDR  0x26
volatile boolean haveData = false;
volatile int value =0;

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}

void loop()
{
  Wire.requestFrom(I2C_SLAVE_ADDR,2);
  if (Wire.available()) {
    value=Wire.read();
  }
  Serial.println (value);
  delay(1500);
}
11  Using Arduino / Audio / Re: MSGEQ7 Works on breadboard. Stops Arduino on PCB. on: January 20, 2013, 09:44:36 am
Finally I found the error. I want to share my approach if others should come in the same situation.
First I desoldered the resistor and some capasitors to see if that changed anything. No result at this path.
Then I carefully bended leg 1 and 2 of MSGEQ7 so only these two legs – the power legs – was attached in the IC socket. Now the PCB worked. Then I added leg 3 and 4 and the PCB stopped working. This way I isolated the problem to leg 3. This is the analog output. Now I could begin to measure resistance (or continuity) from this leg to every possible point on the PCB. Bingo, the reset pin on the Arduino was connected. A little solder between the reset pin and the trace from MSGEQ7 and to the analog pin 0 had escaped my keen eye – or maybe not so keen eye.

That also explain why the program never really started. As soon as MSGEQ7 began to send a signal high enough the Arduino was reset. Maybe turning power on made MSGEQ7 put pin 3 high. I don’t have a scope to test. But now it does not matter anyway.
12  Using Arduino / Audio / Re: MSGEQ7 Works on breadboard. Stops Arduino on PCB. on: January 19, 2013, 06:57:18 am
Here is a link to Fritzing breadboard picture:
https://dl.dropbox.com/u/83914131/soundboxr_bb.png
and schema:
https://dl.dropbox.com/u/83914131/soundboxr_schem.png
13  Using Arduino / Audio / MSGEQ7 Works on breadboard. Stops Arduino on PCB. on: January 19, 2013, 06:52:25 am
My project include SD Card reader, TLC5940 with 555 as external clock and MSGEQ7 for analyzing frequencies in music streamed from SD Card. The frequency spectrum is use to turn LED on and off via TLC5940.
Good news is that everything works on the breadboard. I used Fritzing to help me make an Arduino shield. I used IC sockets for all IC’s so I can test them one by one. If I don’t put my MSGEQ7 in its socket, the code is running and music is streamed. When I power up with MSGEQ7 in its socket I don’t receive anything in my serial monitoring as I normally do. If I measure voltage over pin 1 and 2 on MSGEQ7 it reads 5v as expected. I have spent hours measuring resistance (continuity) on the PCB to check the circuit.
Another thing I observe is that the LED on the Arduino (pin 13) is on. That could indicate that the program never starts because the SD Card uses SPI and initialization make it an SCK pin.
Now my question is, does the fact, that Arduino never start the program indicate what is wrong?
Ps. please don’t answer “Yes, it indicates that the wiring is wrong”. I know that. I need directions to look at, not answers without substance.
14  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: January 13, 2013, 08:01:08 am
Hi Tuttut
I would love to be able to read a text-file from the SD-Card to read some default settings to initialize my music-box. Would that be possible to add to the library without too much effort?
/Allan
15  Using Arduino / Audio / Re: New library for PWM playback from SD cards: SimpleSDAudio on: January 06, 2013, 04:38:59 pm
Thanks for this library. It works like a dream.
For the fun of it, are there any way to speed up or slow down the speed. You know, making Schwarzenegger sound like Mickey mouse?
/Allan
Pages: [1] 2