SMALL - espritmodel.com SMALL - Telemetry SMALL - Radio
Reply
Thread Tools
Old Feb 21, 2013, 05:45 PM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,603 Posts
Thanks Danny.

The mixing is what attracted me as well, and I couldn't find a better solution than this. As far as coupling, I want to be able to follow the throttle stick position up and down. and adjust the "rpm" sound. The solution can be implemented thru software or hardware. I am thinking that when the throttle signal arrives at the receiver, we also pass a message to the Raspi for action. The message will have a value for the throttle and based on the value, it determines which "rpm" sound to play. In that scenario, we can also pass a message for horns, whistles, winches, or any other sound. In fact, the message can be for any action we want the Raspi to handle, not just sound effects, right? Use a header that indicates the action to perform and some values that control the properties for that action. That way we aren't locked into just sound effects. The Raspi just becomes another tool in the chain. Make sense?

Pete
blutoh is offline Find More Posts by blutoh
Reply With Quote
Sign up now
to remove ads between posts
Old Feb 22, 2013, 01:17 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
302 Posts
It makes sense. Do I understand it correct that you want to connect the RC receiver directly to the Raspi? I was thinking of using a Arduino, or my own Atmel328 based board as a interpreter for either RC-channels (I have an Arduino script for that) or NRF-modules. Still researching thou. Like, how to communicatie. Serial, i2c, USB or more basic three 8 bit codes throught the GPIO. Like I said, still researching. I just started with the Raspi, but I think it really has possibilities.

Danny

EDIT: Came across this. Perhaps we can use it:
http://paperpcb.dernulleffekt.de/dok...s:paperduinopi
Dutchraptor is online now Find More Posts by Dutchraptor
Last edited by Dutchraptor; Feb 22, 2013 at 01:47 AM.
Reply With Quote
Old Feb 22, 2013, 08:19 AM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,603 Posts
I am using 'receiver' as a generic term here. In this case the receiver would be the arduino/atmel that is getting the signal from the NRF24L01. We would just need to determine what the communication will be (Serial, i2c, SPI, USB, three 8 bit codes through the GPIO, etc etc) and then create the necessary code on both sides (arduino and raspi) to implement it.
blutoh is offline Find More Posts by blutoh
Reply With Quote
Old Feb 22, 2013, 03:51 PM
made of fire and pop rocks
bgnome's Avatar
Richmond Virginia
Joined Oct 2009
1,711 Posts
Ive stated else where that the pi, using a standard OS does not seem feasible for real time operations as Wheezy is a multi tasking OS and your serial communications from pi to Atmega will be lagged by the nature of the environment.
A custom RC OS seems to be in order. There should already be something out there
bgnome is offline Find More Posts by bgnome
Reply With Quote
Old Feb 22, 2013, 04:40 PM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,603 Posts
Hi Beer Gnome,

I agree, and It won't be. The arduino will be handling realtime duties. The pi will be handling sound system and a few other things where some latency won't be an issue. At a later stage the pi will be used to capture data. video. etc.

Pete
blutoh is offline Find More Posts by blutoh
Last edited by blutoh; Feb 22, 2013 at 05:02 PM.
Reply With Quote
Old Feb 22, 2013, 05:47 PM
Registered User
United States, PA
Joined Feb 2013
92 Posts
Blutoh,

I followed your instructions and it worked perfectly. Thanks for posting. I will be following your thread to see how things progress and what you and dutchraptor come up with as the final soultion.

HD
Heavy_Duty is offline Find More Posts by Heavy_Duty
Reply With Quote
Old Feb 24, 2013, 09:51 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
302 Posts
Blutoh,
I have a Firmata link with the Arduino with Python. It read and writes directly to the ports, analog and digital. Next step will be exploring if I can get the commands to be linked to the sounds. After that I'll try to link serial command comming in the arduino to Pythen by Firmata.

for the Pyfirmata:
https://github.com/tino/pyFirmata

Install the pyfirmata from the RootTerminal: python setup.py install

for examples
https://bitbucket.org/fab/pyfirmata/...77527/examples

Perhaps you can use this info too.

Danny

PS: I cannot seem to get stuff to run outside python in the terminal like soundfx.py. How do I do that. -> found it chmod problem
Dutchraptor is online now Find More Posts by Dutchraptor
Last edited by Dutchraptor; Feb 24, 2013 at 10:47 AM.
Reply With Quote
Old Feb 24, 2013, 10:32 AM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,603 Posts
Quote:
Originally Posted by Dutchraptor View Post
......................,,,,,,,
Perhaps you can use this info too..............................

PS: I cannot seem to get stuff to run outside python in the terminal like soundfx.py. How do I do that.
Danny,

I will download it and start modifying the code. I don't have any arduino's yet so I will post code here, maybe you can test it?

To get stuff to run outside python ide (idle) in the terminal:
Are you getting any error messages? If so, let me know what they are.
Try running like this from a terminal window, with all parameters expicitly written:

sudo python ~/soundfx/soundfx.py

This assumes you have the soundfx folder created, and soundfx.py resides in that folder. I will attempt to make a video to demonstrate.

Pete
blutoh is offline Find More Posts by blutoh
Reply With Quote
Old Feb 24, 2013, 12:28 PM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,603 Posts
A qucik video:

Sound System menu demo (1 min 38 sec)
blutoh is offline Find More Posts by blutoh
Reply With Quote
Old Feb 24, 2013, 01:58 PM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
302 Posts
Thanks for the effort, but due to my sleepiness (to early out of bed from the night-shift), I wasn't very clear. I meant that any programs/scripts made in python, I could only run them in the python-shell. After checking I found that the soundfx.py had a different color and attributes then my little thing. After the chmod 775 from page 1, my own stuff also started.

Still learning Linux and all the differences with windows. Now let's see how we can get it to understand that when a button is clicked, only 1 value changes and it doesn't need to keep checking useless stuff that only bounce useless things back.

Danny
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Feb 24, 2013, 03:09 PM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,603 Posts
OK Danny,

Looks like you had file permission issue .

I have attached a new version of the program which reads pins directly. One pin for each sound effect. We can always change it to serial, I just want to see if we can get the pin interaction working directly.

A couple of points:
  • GPIO voltage levels are 3.3 V on the raspi, and are not 5 V tolerant as on Arduino. There is no over-voltage protection on the raspi board BE CAREFUL!
  • The pin configuration I am using in the program is the BCM physical layout, same as in the pins header of raspi version 2 aka B, or the second column in this list. If you are using raspi version 1, they may be different! Check your pins documentation.
  • To access the pins, you must run with root privileges: sudo ~/soundfx/soundfx2.py
+----------+------+--------+------+-------+
| wiringPi | GPIO | Name | Mode | Value |
+----------+------+--------+------+-------+
| 0 | 17 | GPIO 0 | IN | Low |
| 1 | 18 | GPIO 1 | IN | Low |
| 2 | 27 | GPIO 2 | IN | Low |
| 3 | 22 | GPIO 3 | IN | Low |
| 4 | 23 | GPIO 4 | IN | Low |
| 5 | 24 | GPIO 5 | IN | Low |
| 6 | 25 | GPIO 6 | IN | Low |
| 7 | 4 | GPIO 7 | IN | Low |
| 8 | 2 | SDA | IN | High |
| 9 | 3 | SCL | IN | High |
| 10 | 8 | CE0 | IN | Low |
| 11 | 7 | CE1 | IN | Low |
| 12 | 10 | MOSI | IN | Low |
| 13 | 9 | MISO | IN | Low |
| 14 | 11 | SCLK | IN | Low |
| 15 | 14 | TxD | ALT0 | High |
| 16 | 15 | RxD | ALT0 | High |
| 17 | 28 | GPIO 8 | IN | Low |
| 18 | 29 | GPIO 9 | IN | Low |
| 19 | 30 | GPIO10 | IN | Low |
| 20 | 31 | GPIO11 | IN | Low |
+----------+------+--------+------+-------+

I tested by momentarily setting the appropriate pin high, then low again, via software. I don't have a way to test via hardware.
Please test when you have time and let me know if it works for you.

Thanks,
Pete

EDIT: For a quick synopsis and the latest installation package, go directly to this post.
blutoh is offline Find More Posts by blutoh
Last edited by blutoh; Mar 31, 2013 at 12:48 PM. Reason: spelling
Reply With Quote
Old Feb 24, 2013, 03:13 PM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,603 Posts
The new code:

EDIT: For a quick synopsis and the latest installation package, go directly to this post.
blutoh is offline Find More Posts by blutoh
Last edited by blutoh; Apr 10, 2013 at 02:15 PM.
Reply With Quote
Old Feb 24, 2013, 06:56 PM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,603 Posts
I was able to test the sound system with this script. It works by momentarily setting the pins high to trigger the sound, same as a hardware connection would do. It requires the gpio utility to be installed in order to work. The gpio utility is part of wiringPi library and is installed wth it. WiringPi installation instructions are here.

To use the test script:
  • Change the file name from testmnu.txt to testmnu (NO extension)
  • Copy testmnu to you raspi in the same folder as soundfx2.py
  • Change permissions, from the $ prompt: chmod 755 ./testmnu
  • Open two (2) terminals on raspi
  • In one terminal start the soundfx program: sudo ./soundfx2.py
  • in the other run the test script: sudo ./testmnu
  • from the menu you can coose options and the pins will be toggled high and low to test them
Pete

[EDIT: For a quick synopsis and the latest installation package, go directly to this post.
blutoh is offline Find More Posts by blutoh
Last edited by blutoh; Apr 10, 2013 at 02:15 PM.
Reply With Quote
Old Feb 25, 2013, 08:59 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
302 Posts
Blutoh,
I have a little code for you if you want to go the Arduino Route like I did. It's a sample with which I can read and extract which data is send and couple it to a function. We can combine this piece of code with your piece of code for the sound-part. The test is made with 1 potentiometer (10K) on analog 1 for reading/sending analog values. And I have on pin 5 and pin 6 a switch with a pull-down resistor (10K) to ground. The commands are added and given a groupnumber (in this case 2). After reading 1000 (for the extration of the analog value) or 2000 (for the digital value) are substracted. The digital values are then checked if a function is active or not.

Arduino and Python (in the shell, I still can't get it in the Terminal) are checked: No Firmate needed so I can read pins and send strings

Code:
// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin6 = 6;     // the number of the pushbutton pin
const int buttonPin5 = 5;     // the number of the pushbutton pin
const int analogInPin = A1;  // Analog input pin that the potentiometer is attached to
const int analogbuffer = 0; // 

// Variables will change:
int buttonState5;             // the current reading from the input pin
int lastButtonState5 = LOW;   // the previous reading from the input pin
int buttonState6;             // the current reading from the input pin
int lastButtonState6 = LOW;   // the previous reading from the input pin
int buttonSend = 2000;
int buttonSendOld = 0;
int Sending = 0;
  int sensorValue = 0;        // value read from the pot
  int outputValue = 0;        // value output to the PWM (analog out)
  int outputValueOld = 0;
  
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers

void setup() {
    // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
  pinMode(buttonPin5, INPUT);
  pinMode(buttonPin6, INPUT);
}

void loop() {
  // read the state of the switch into a local variable:
  int reading5 = digitalRead(buttonPin5);
  int reading6 = digitalRead(buttonPin6);
  
  // check to see if you just pressed the button 
  // (i.e. the input went from LOW to HIGH),  and you've waited 
  // long enough since the last press to ignore any noise:  
  // If the switch changed, due to noise or pressing:
  if (reading5 != lastButtonState5) {
    // reset the debouncing timer
    lastDebounceTime = millis();
        buttonState5 = reading5;
    if (reading5 == HIGH){buttonSend=buttonSend+128;}
    if (reading5 == LOW){buttonSend=buttonSend-128;}
  }
   if (reading6 != lastButtonState6) {
    // reset the debouncing timer
    lastDebounceTime = millis();
        buttonState6 = reading6;
    if (reading6 == HIGH){buttonSend=buttonSend+64;}
    if (reading6 == LOW){buttonSend=buttonSend-64;}
  } 
  
  if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:
  }
  
  // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
  lastButtonState5 = reading5;
  lastButtonState6 = reading6;
  
    // read the analog in value:
  sensorValue = analogRead(analogInPin);            
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 1000, 1255);  

if (outputValue != outputValueOld){
  Serial.println(outputValue); 
outputValueOld = outputValue;
}
  
  // if anything changes in button state, send it
  if (buttonSend != buttonSendOld){
  Serial.println(buttonSend);
  buttonSendOld = buttonSend;}
  
  delay(20);
}
Python Code:

Code:
#Serial commands between 1000 and 1500 are analog readings from arduino
#Serial commands between 2000 and 2255 are digital readings from arduino
#Now this works, we can expand the functiongroups and functions
#The connection with a Nano with a NRF24L01 is also open or
#a Arduino Mega with a NRF24L01 and functions hooked up

import serial
import string

ARDUINO =  "/dev/ttyACM0"

def main():
        ser = serial.Serial(ARDUINO, 9600)
        prevVal = None

        while 1:
                # Read the serial value
                ser.flushInput()
                serialValue = ser.readline().strip()
                # Catch any bad serial data:
                try:
                        #c = convert + int(serialValue)
                        c = int(serialValue)
                except ValueError:
                        serialValue = 0
                try:
                        if serialValue != prevVal and c > 1000 and c < 1500:
                                # Print the value if it differs from the prevVal:
                                c = c - 1000 # bring back to normal 8 bit numbers
                                print "AnalogVal:",c, "  Serialreceive:",serialValue
                                prevVal = serialValue

                        elif serialValue != prevVal and c > 1999 and c < 2256:
                                c = c - 2000 #bring back to normal 8 bit numbers
                                try:
                                        if c == 0:
                                                print "All functions Off  8-Bitcommand:",c,  "  Serial command received:",serialValue
                                        if c >= 128:
                                                print "Function 1: on  8-Bitcommand:",c, "  Serial command received:",serialValue
                                                c = c -128
                                        if c >= 64:
                                                print "Function 2: on  8-Bitcommand:",c, "  Serial command received:",serialValue
                                                c =c -64
                                        # this can go on with the value 32, 16, 8, 4, 2 and 1
                                
                                except ValueError:
                                        pass

                except ValueError:
                        pass
                
if __name__ == '__main__':
    main()
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Reply


Thread Tools