adafruit / adafruit_circuitplayground Goto Github PK
View Code? Open in Web Editor NEWlibrary for Circuit Playground board
library for Circuit Playground board
I have a game demo I could add to the library that demonstrates the accelerometer and other components of the Circuit Playground. Are you accepting user contributions of demos? It could be placed in the examples folder or a new contrib folder could be used for community contributions. Video of the game demo can be seen at https://youtu.be/JV2Jdn3KFzo
If there is another way to contribute to a Circuit Playground demo repository, let me know. I think it would be great to have more examples to get more people excited about the device and I would be happy to contribute code to it.
in Adafruit_CPlay_Speaker::set() in Adafruit_CPlay_Speaker.cpp, i believe
TCCR4A = value;
should be changed to OCR4A = value;
Also in talkie.cpp in Adafruit_CPlay_Speaker::say() change TCCR4A = 0x7F; to OCR4A = 0x7F;
Suggest you add two new functions to augment CircuitPlayground.rightButton and .leftButton
CircuitPlayground.debounced.leftButton
CircuitPlayground.debounced.rightButton
or something similar to help the less experienced and educators on getting a fully debounced switch state rather than having to add in a bunch of code to do the debouncing by themselves.
Thank you for your consideration. Mike
Ref. this forum thread:
https://forums.adafruit.com/viewtopic.php?f=58&t=102459
Ref. current library documentation:
https://learn.adafruit.com/circuit-playground-lesson-number-0/mini-speaker#library-reference
Ref. CircuitPlayground library playTone() function:
https://github.com/adafruit/Adafruit_CircuitPlayground/blob/master/Adafruit_CircuitPlayground.cpp#L79
Ref. Arduino library tone() function:
https://www.arduino.cc/en/Reference/Tone
https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/Tone.cpp#L243
The current Circuit Playground playTone()
function simply calls the Arduino library tone()
function. The tone generation is done using timer interrupts. The call to tone()
configures the timer and returns. This leads to the following lines of code only producing the second (800Hz) sound:
CircuitPlayground.playTone(500, 1000);
CircuitPlayground.playTone(800, 1000);
This is fixed quite simply using delay():
CircuitPlayground.playTone(500, 1000); delay(1000);
CircuitPlayground.playTone(800, 1000); delay(1000);
However, a blocking behaviour may be better suited for CircuitPlayground. Or at least the option for both (blocking/non-blocking) with blocking being the default.
The #include in Adafruit_CircuitPlayground.h for Adafruit_CPlay_NeoPixel.h (line 18) calls for Adafruit_CPlay_Neopixel.h (lower case p) which doesn't find the file on case sensitive file systems (Linux)
Arduino board: Circuit playground
Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.5
Current example programs are broken . All generate errors on compile example shown in attached TXT
New Text Document (4).txt
Hi I tried this program on the Circuit Playground Blue Fruit and everything works perfect, save the capacitive touch piano. It does still play the series of tones independent of the touch input.
I adjusted the cap cut off values up and down by 200, though did not change anything.
Wondering if there is some alternate way the capacitive touch / tones are accessed in the Bluefruit model?
Arduino board: CP Blue Fruit
Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.16
Using code included in the Arduino IDE Adafruit example. Downloaded 12/20/21
List the steps to reproduce the problem below (if possible attach a sketch or
copy the sketch code in too): compiled and uploaded unedited code to CP Bluefruit
Thank you
~/Arduino/libraries/Adafruit_Circuit_Playground/examples/demo.ino
~/Arduino/libraries/Adafruit_Circuit_Playground/utility/Adafruit_CPlay_Mic.cpp: In member function 'int Adafruit_CPlay_Mic::peak(uint16_t)':
~/Arduino/libraries/Adafruit_Circuit_Playground/utility/Adafruit_CPlay_Mic.cpp:27:37: error: 'analogPinToChannel' was not declared in this scope
channel = analogPinToChannel(4); // Pin A4 to ADC channel
^
~/Arduino/libraries/Adafruit_Circuit_Playground/utility/Adafruit_CPlay_Mic.cpp: In member function 'void Adafruit_CPlay_Mic::capture(int16_t*, uint8_t)':
~/Arduino/libraries/Adafruit_Circuit_Playground/utility/Adafruit_CPlay_Mic.cpp:84:37: error: 'analogPinToChannel' was not declared in this scope
channel = analogPinToChannel(4); // Pin A4 to ADC channel
^
exit status 1
Error compiling for board Arduino/Genuino Uno.
In the dm-mic-spl fork, running the soundPressureLevel example. Open serial monitor (not the plotter) and (when quiet) you'll see some "inf"s mixed in with the numeric output. Only happens on AVR; ARM seems unaffected. @dhalbert
This line added a pin config change to end()
:
https://github.com/adafruit/Adafruit_CircuitPlayground/blob/master/utility/Adafruit_CPlay_Speaker.cpp#L41
and nothing in the loop()
of the combadge example turns it back to output.
Example sketch can be fixed by adding a call to .speaker.begin()
in the loop()
, but not sure if this behavior change was intended for the library.
Arduino IDE says:
c:\Users\xxx\Documents\Arduino\libraries\Adafruit_CircuitPlayground-1.12.0/utility/CP_Boards.h:746:2: error: #error "Please edit CP_Boards.h with a hardware abstraction for this board"
746 | #error "Please edit CP_Boards.h with a hardware abstraction for this board"
| ^~~~~
I found that there are a lot of descriptions of the MCU in CP_Boards.h file,
but the number of #define constants/variables is different,
so I don't know how to write it。 -_-!
I am using the CPB (Circuit Playground Bluefruit). The readings for the motionX and motionY variables are flipped in direction, which means they have the opposite sign compared to the coordinate direction on board.
When using an external neo pixel on pin A1 (as suggested in multiple posts on adafruit.com) the neo pixels don't light up.
This is due to lines 70 to 84 (Adafruit_CircuitPlayground.cpp) that re-map A1 for cap touch - even though there is nothing mentioned in the H file about its usage.
Fix:
comment out line 70 to 84 if you are not using cap touch.
or
Circuit playground begin() should be overloaded when you pass an external neo pixel pin.
Re this thread:
https://forums.adafruit.com/viewtopic.php?f=58&t=157171
Simple issue. Just some preprocessor stuff.
Recent updates added #if
that uses __SAMD21__
__SAMD21G18A__
Hi,
This is a great library but I struggled with using it because I didn't know where to look for the the available methods. I just happened to stumble upon some of the methods that I needed in tutorials and then I found the rest in the header files.
I think the addition of a README.md
file would be beneficial to users.
Something along these lines:
# Adafruit_CircuitPlayground
## Methods
### boolean CircuitPlayground.begin(uint8_t brightness)
Initializes the library.
...
### boolean leftButton(void)
check the state of the left button.
### boolean rightButton(void)
check the state of the right button.
...
### void CircuitPlayground.senseColor(uint8_t& red, uint8_t& green, uint8_t& blue)
Perform basic RGB color sensing.
The return values are assigned to the parameters.
### uint32_t CircuitPlayground.senseColor()
Perform basic RGB color sensing.
...
I was eventually able to do what I wanted, so I do not thing this is required, but I do think it will
lower the barrier to entry.
Thank you!
On Circuit Playground Express, calling CircuitPlayground.readCap()
makes Adafruit_NeoPixel_ZeroDMA display random pixels. Try with the following sketch:
#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_NeoPixel_ZeroDMA.h>
#define PIXELS_PIN 8
#define PIXELS_NUM 10
#define TOUCH_PIN A1
Adafruit_NeoPixel_ZeroDMA pixels(PIXELS_NUM, PIXELS_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
CircuitPlayground.begin();
pixels.begin();
pixels.setBrightness(24);
}
void loop() {
int c = CircuitPlayground.readCap(TOUCH_PIN);
pixels.fill(pixels.Color(128, 0, 255));
pixels.show();
delay(10);
}
This is just the simplest example to show the problem without additional hardware. I'm in fact trying to use Adafruit_NeoMatrix_ZeroDMA on pin A2, but it exhibits exactly the same problem. When commenting out the readCap()
line everything works as expected.
Arduino board: Circuit Playground Express
Arduino IDE version: 1.8.8
Using Adafruit SAMD Boards 1.2.9 definition from https://adafruit.github.io/arduino-board-index/package_adafruit_index.json (otherwise Adafruit_NeoMatrix_DMA doesn't work at all)
Installed Arduino's SAMD Boards via the Board manager (I had no luck at all to get CPE working with the Adafruit's AVR Boards manager)
Installed the last version of Circuit Playground Library (1.6.9) via the Library manager
Run the demo example.
The example won't compile and I Got an error message saying two things (macOs):
/Applications/Arduino/libraries/Adafruit_CircuitPlayground/utility/CP_Boards.h:708:2: error: #error "Please edit Boards.h with a hardware abstraction for this board"
That two libraries were found and only one was used. (I read this thread which clarifies a bit the situation)
After multiple reinstallation of the board manager and the library, I finally got the examples to compile (with a lot of warnings!) and upload on board by changing the #include
directive from <Adafruit_CircuitPlayground.h>
to <Adafruit_Circuit_Playground.h>
(notice the second underscore).
I am a bit puzzled by that behaviour and wanted to know if I am alone.
If not, maybe we could fix that by changing the #include
in all examples ?
It seems that capacitive touch is now working on CPB. For example this doesnt read anything:
CircuitPlayground.readCap(0)
Pinning seems to be different because some caps work, for example A6 = 0, A7 = 1 ... etc.
#include <Adafruit_CircuitPlayground.h>
void setup() {
CircuitPlayground.begin();
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A1);
//CircuitPlayground.readCap(A2);
Serial.println(sensorValue);
delay(20);
}
This code works until CircuitPlayground.readCap(A2);
is uncommented. Once I do that, analogRead(A1) can never reach 0. Even A1 is tied to GND. It seems capacitive touch used QTOUCH lib so I'm not able to fix it myself this time.
Library Description is incorrect. From library.properties
:
sentence=All in one library to control Adafruit's Circuit Playground board.
paragraph=All in one library to control Adafruit's Circuit Playground board. Requires no other dependencies and exposes all Circuit Playground components in a simple to use class.
commit: 9b216be added a depends=
line to library.properties
, creating six dependencies, which in turn bring in an even larger tree of sub-dependencies.
The description is no longer accurate and should be changed to reflect this.
TLDR: Thermistor Beta constant should be 3380.
Ref. this forum thread:
https://forums.ahttps://forums.adafruit.com/viewtopic.php?f=58&t=105254dafruit.com/viewtopic.php?f=58&t=105254
Ref. this datasheet for the Murata NTC NCP15XH103F03RC:
http://www.murata.com/~/media/webrenewal/support/library/catalog/products/thermistor/ntc/r44e.ashx
Datasheet specifies a beta constant of 3380. Current library #defines it to be 3950. The datasheet linked above provides a table of actual resistance vs. temperature values on page 15. Using that, can compare results for Steinhart approximation with different beta constants. As can be seen in the figure below, 3380 provides better results.
Arduino board: Adafruit Circuit Playground Classic
Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.6 (Hourly)
When flashing the Circuit Playground library's megademo example, I was presented with an error citing that Adafruit_SleepyDog.h
was missing. After searching the github I only see it referenced one other place, which is .travis.yml. Specifically:
install:
- arduino --install-library "Adafruit LED Backpack Library","Adafruit GFX Library","Adafruit SleepyDog Library","Adafruit Zero FFT Library"
I checked my libraries and found that Adafruit SleepyDog Library
was not installed, despite having just recently installed the Adafruit Circuit Playground library. I tried deleting the Playground library and then reinstalling it, which worked fine, but SleepyDog still was not present. Only after searching for it manually in the library manager and installing it did megademo compile and flash correctly.
I'd venture to guess something is going wrong with the install script. I wasn't aware libraries could even install other libraries as dependencies. I assume that's what's supposed to be happening here and that'd be a neat and interesting feature if it worked :) Ideas?
My hourly is a bit old but it's still newer than the latest release:
1.8.6 Hourly Build 2018/04/19 10:37
Fairly easy, but somewhat non-obvious since there is a "built in" implementation for neopixel support here. A new example would help demonstrate how this should be done.
Re this thread:
https://forums.adafruit.com/viewtopic.php?f=58&t=152174
Seems to be related to low level register writes and timer setup in Adafruit_CPlay_Speaker::begin()
:
Adafruit_CircuitPlayground/utility/Adafruit_CPlay_Speaker.cpp
Lines 18 to 29 in 991fd39
Hi!
I noticed there is no implemented support for sending raw IR data.
The relevant function is written in IRLib_HashRaw.h, which had no include statement in IRLibCPE.h, and in addition the only linkage was broken:
The next line is a line is in IRLib_HashRaw.h:
#define IR_SEND_RAW case 0: IRsendRaw::send((uint16_t*)data,data2,khz); break;
The IR_SEND_RAW macro is used in IRLibCombo.h in IRsend class, in the send method, in order to send raw transmission. That will always result as an illegal cast between uint32_t to uint16_t* .
As a result it's impossible to use this method from the built-in IRsend object in the main object of CircuitPlayground.
I submitted PR of how I think this should be implemented.
Hope that helps :)
Idan
Header say everything :-)
Something is wrong in this version history.
Pleas check it, THX!
Re this thread:
https://forums.adafruit.com/viewtopic.php?f=58&t=174956#p854766
The samples
parameter for readCap()
does not appear to be used for the CPX using FreeTouch.
This is a recommendation for ease of use, regarding the accelerometer mouse code. Once a user codes the mouse, reprogramming the circuit playground can be difficult, forcing the user to then use the mouse to navigate the IDE. This was my experience, and I think other users may have the same issue. The problem could easily be resolved, by including the lines:
....
if (!CircuitPlayground.slideSwitch()) {
return;
}
...
in then the users will have a way to regain normal mouse operations.
Source here:
https://github.com/adafruit/Adafruit_CircuitPlayground/blob/master/examples/accel_mouse/accel_mouse.ino
Just need to configure digital 11 for output somewhere. The removal of the call to speaker.begin()
in #41 removed that part of the setup.
Discovered while helping here:
https://forums.adafruit.com/viewtopic.php?f=58&t=154242
#include <Adafruit_CircuitPlayground.h>
void setup() {
CircuitPlayground.begin();
//uncomment this and it will work again
//pinMode(11, OUTPUT);
CircuitPlayground.speaker.off();
}
void loop() {
CircuitPlayground.playTone(500, 100);
delay(1000);
}
It creates serious problems for anyone working with malloc and I don't see it serving any purpose here since there is only one NeoPixel strip on the board and it is statically allocated. For more info, see:
Thank you for opening an issue on an Adafruit Arduino library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:
Do not use GitHub issues for troubleshooting projects and issues. Instead use
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
something isn't working as expected. In many cases the problem is a common issue
that you will more quickly receive help from the forum community. GitHub issues
are meant for known defects in the code. If you don't know if there is a defect
in the code then start with troubleshooting on the forum first.
If following a tutorial or guide be sure you didn't miss a step. Carefully
check all of the steps and commands to run have been followed. Consult the
forum if you're unsure or have questions about steps in a guide/tutorial.
For Arduino projects check these very common issues to ensure they don't apply:
For uploading sketches or communicating with the board make sure you're using
a USB data cable and not a USB charge-only cable. It is sometimes
very hard to tell the difference between a data and charge cable! Try using the
cable with other devices or swapping to another cable to confirm it is not
the problem.
Be sure you are supplying adequate power to the board. Check the specs of
your board and plug in an external power supply. In many cases just
plugging a board into your computer is not enough to power it and other
peripherals.
Double check all soldering joints and connections. Flakey connections
cause many mysterious problems. See the guide to excellent soldering for examples of good solder joints.
Ensure you are using an official Arduino or Adafruit board. We can't
guarantee a clone board will have the same functionality and work as expected
with this code and don't support them.
If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:
Arduino board: INSERT ARDUINO BOARD NAME/TYPE HERE
Arduino IDE version (found in Arduino -> About Arduino menu): INSERT ARDUINO
VERSION HERE
List the steps to reproduce the problem below (if possible attach a sketch or
copy the sketch code in too): LIST REPRO STEPS BELOW
Thank you for opening an issue on an Adafruit Arduino library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:
Do not use GitHub issues for troubleshooting projects and issues. Instead use
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
something isn't working as expected. In many cases the problem is a common issue
that you will more quickly receive help from the forum community. GitHub issues
are meant for known defects in the code. If you don't know if there is a defect
in the code then start with troubleshooting on the forum first.
If following a tutorial or guide be sure you didn't miss a step. Carefully
check all of the steps and commands to run have been followed. Consult the
forum if you're unsure or have questions about steps in a guide/tutorial.
For Arduino projects check these very common issues to ensure they don't apply:
For uploading sketches or communicating with the board make sure you're using
a USB data cable and not a USB charge-only cable. It is sometimes
very hard to tell the difference between a data and charge cable! Try using the
cable with other devices or swapping to another cable to confirm it is not
the problem.
Be sure you are supplying adequate power to the board. Check the specs of
your board and plug in an external power supply. In many cases just
plugging a board into your computer is not enough to power it and other
peripherals.
Double check all soldering joints and connections. Flakey connections
cause many mysterious problems. See the guide to excellent soldering for examples of good solder joints.
Ensure you are using an official Arduino or Adafruit board. We can't
guarantee a clone board will have the same functionality and work as expected
with this code and don't support them.
If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:
Arduino board: Circuit Playground Express rev G
Arduino IDE version (found in Arduino -> About Arduino menu): Mu 1.0.0.beta15, CircuitPython 2.2.3
List the steps to reproduce the problem below (if possible attach a sketch or
copy the sketch code in too): LIST REPRO STEPS BELOW
Program to demonstrate writing out string data via HID keyboard emulation on CPX:
import time
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_circuitplayground.express import cpx
kbd = Keyboard()
layout = KeyboardLayoutUS(kbd)
while True:
if cpx.button_a:
# Type your name followed by Enter (a newline).
layout.write('Kim Possible\n')
elif cpx.button_b:
# Type out the name of your development board
layout.write('Circuit Playground Express\n')
time.sleep(0.1)
I can press button A and get the text out.
With one press of button B, it will print partial text then through the following error
soft reboot
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
File "code.py", line 19, in
File "adafruit_hid/keyboard_layout_us.py", line 209, in write
MemoryError: memory allocation failed, allocating 460 bytes
Press any key to enter the REPL. Use CTRL-D to reload.
A bit time sensitive due to getting my CPX book to publisher this month. Thanks, Mike
I am having trouble with the Speech examples… Getting just buzz and hiss, no speech. Arduino IDE 1.8.5, Playground Circuit 1.8.0 library. Chip is Playground Circuit classic. Does anyone have a clue?
Rest of the examples seem to work… Tried on Windows and OSX and in Arduino Web Editor – same story, no speech, just hissing and buzzing.
Please, suggest?
Thanks,
Roman
Sometimes when uploading code the NeoPixel below the GND pin next to the USB connector will light green and stay on. On next upload it will turn off. This was the code I was using:
void setup() {
CircuitPlayground.begin(); // initialize the Circuit Playground library
}
void loop() {
int value , sound;
if(CircuitPlayground.slideSwitch()) { // if the slide switch is on
value = CircuitPlayground.lightSensor(); // read the light sensor
sound = map(value, 5, 1000, 131, 1760); // map light values to music values
CircuitPlayground.playTone(sound, 100); // play sound for 100 milliseconds
}
}
Also I had run a sketch to light the NeoPixels in Pokemon colors. I then uploaded a sketch that did not do anything with the NeoPixels (it just played tones on the speaker). The NeoPixels stayed lit even with a new sketch loaded.
The brute force method would be for the begin function to make sure all the NeoPixels are off but there might be a more specific issue to fix.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.