Quantcast
Channel: Learn with BlocklyProp — Parallax Forums
Viewing all 293 articles
Browse latest View live

Welcome! - BlocklyProp Questions with the S3

$
0
0
Looks like this will be the "proper" place for questions regarding BlocklyProp questions in general and BlocklyProp Questions with the S3! (I'll be watching in the Robotics section too!)

Welcome educators and students - report problems, ask questions (no question is dumb - trust me - somebody else wants to know and is afraid to ask!) and help us improve BlocklyProp and the all the Learn Resources for the S3. Share ideas - even if you can't figure out how to make them work. We'll make them into something or learn new tricks. Share what you are doing too! Post a video, a BlocklyProp code link, a photo of you and your team - I know that I want to see what you're up to and so does the Parallax team!

Let's keep building and learning from one another

Better use of C++'s "using" keyword

$
0
0
I do quite like Java's import statement. I wish C++ had an equivalent, rather than using a preprocessor to pull in header files. Nonetheless, I feel that "using <namespace>::<class>" is a lot better than no "using" keyword or "using namespace <namespace>". I just found out that this is possible, so I have to share :D

I've just turned this code...
#include <PropWare/PropWare.h>
#include <PropWare/gpio/pin.h>

int main () {
    const PropWare::Pin led1(PropWare::Pin::Mask::P17, PropWare::Pin::Dir::OUT);
    led1.start_hardware_pwm(4);

    const PropWare::Pin led2(PropWare::Pin::Mask::P16, PropWare::Pin::Dir::OUT);
    while (1) {
        led2.toggle();
        waitcnt(CLKFREQ / 4 + CNT);
    }
}

into this:
#include <PropWare/PropWare.h>
#include <PropWare/gpio/pin.h>

using PropWare::Pin;

int main () {
    const Pin led1(Pin::P17, Pin::Dir::OUT);
    led1.start_hardware_pwm(4);

    const Pin led2(Pin::P16, Pin::Dir::OUT);
    while (1) {
        led2.toggle();
        waitcnt(CLKFREQ / 4 + CNT);
    }
}

That's much better! And still much safer than "using namespace PropWare" at the top :)

L3G4200D Gyroscope Data Using SPI

$
0
0
Hello,

I completed the SPI example on the Learn website given here: http://learn.parallax.com/tutorials/language/propeller-c/propeller-c-simple-protocols/spi-example

I would now like to read data from the Parallax L3G4200D gyroscope module using the 3-wire SPI mode. Here is my code so far:
/*
  Gyroscope Test XYZ Axes.c
*/
#include "simpletools.h"                                          // Include simple tools

const int DATA = 12;
const int CLK = 13;
const int CS = 14;

const int CTRL_REG1 = 0x20;
const int CTRL_REG2 = 0x21;
const int CTRL_REG3 = 0x21;
const int CTRL_REG4 = 0x22;
const int STATUS_REG = 0x27;
unsigned char statusReg;

signed char x;                                                    // X-axis value
signed char y;                                                    // Y-axis value
signed char z;                                                    // Z-axis value

int main()                                                        // Main function
{
  high(CS);                                                       // CS line high (inactive)
  low(CLK);                                                       // CLK line low
  
  low(CS);                                                        // CS line low (start SPI)
  shift_out(DATA, CLK, MSBFIRST, 16, 0b0010000000011111);          // Write CTRL_REG1
  shift_out(DATA, CLK, MSBFIRST, 16, 0b0010001000001000);          // Write CTRL_REG3
  shift_out(DATA, CLK, MSBFIRST, 16, 0b0010001110000001);          // Write CTRL_REG4
  high(CS);                                                       // CS line high (stop SPI)
 
  while(1)                                                         // Main loop
  {
    low(CS);                                                       // CS low selects chip
    shift_out(DATA, CLK, MSBFIRST, 8, 10100111);                        // Send read register address, x-axis
    statusReg = shift_in(DATA, CLK, MSBPOST, 16);                               // Get value from register
    
    if(statusReg == 0)
    {
      shift_out(DATA, CLK, MSBFIRST, 8, 10100111);                        // Send read register address, x-axis
      statusReg = shift_in(DATA, CLK, MSBPOST, 16);                               // Get value from register
    }
    else
    {
      shift_out(DATA, CLK, MSBFIRST, 8, 10100111);                        // Send read register address, x-axis
      statusReg = shift_in(DATA, CLK, MSBPOST, 16);                               // Get value from register
      
            
      
      
    

    //x = shift_in(DATA, CLK, MSBPRE, 8);                            // Get value from register
    
    /*
    cmd = YOUT8 & readMask;
    shift_out(DATA, CLK, MSBFIRST, 7, cmd);                        // Send read register address, y-axis
    shift_out(DATA, CLK, MSBFIRST, 1, 0b0);                        // Send don't care value
    y = shift_in(DATA, CLK, MSBPRE, 8);                            // Get value from register
    
    cmd = ZOUT8 & readMask;
    shift_out(DATA, CLK, MSBFIRST, 7, cmd);                        // Send read register address, z-axis
    shift_out(DATA, CLK, MSBFIRST, 1, 0b0);                        // Send don't care value
    z = shift_in(DATA, CLK, MSBPRE, 8);                            // Get value from register
    high(CS);   
    */                                                   // De-select chip
    
   // print("%cx=%d  y=%d  z=%d%c", HOME, x, y, z, CLREOL);          // Display measurement
    
    pause(500);                                                    // Wait 0.5s before repeat    
  }  
}

I am trying to develop this code without using the bit masks first so I can make sure I understand everything. My first question deals with reading data from the device. In the datasheet on page 26, we see:

"The SPI read command is performed with 16 clock pulses:
Bit 0: READ bit. The value is 1.
Bit 1: MS bit. When 0, do not increment address; when 1, increment address in multiple
reading.
Bit 2-7: address AD(5:0). This is the address field of the indexed register.
Bit 8-15: data DO(7:0) (read mode). This is the data that is read from the device (MSb first).
The multiple read command is also available in 3-wire mode."

Why is there a bit 8-15? Isn't that the data we are trying to get? I thought it would be something like this (taken from my code above):
shift_out(DATA, CLK, MSBFIRST, 8, 10100111);                        // Send read register address, x-axis
    statusReg = shift_in(DATA, CLK, MSBPOST, 16);                               // Get value from register

Where we are sending a read bit (1) followed by 7 bits containing the address of STATUS_REG. Then the shift_in function would display the values in that register. However, the datasheet seems to say that there should be 16 bits. Can someone please explain what I'm missing and if I am generally heading in the right direction?

Thank you,
David

Circles, arcs and spirals with S3 and Blockly

$
0
0
Hello everybody,
From an old thread: "Nikos' Fibonacci Spiral Challenge" Whit and I, had analyzed how we can make circles, arcs and spirals with S2 and GUI.
The Math theory doesn't change, however working with Blockly we need a differen approach.
This is all about that I'll try to explain in the next lines:
First challenge : How to make a circle with specific radius R with S3 and Blockly:
s3_circles_with_Blockly.png

BlocklyProp and ActivityBoard - Terminal Input

$
0
0
For the blocks:
Communicate/Terminal/TerminalReceiveTextStoreIn
Communicate/Terminal/TerminalReceiveNumberStoreIn

I don't see on the terminal (window titled "Console") an interface to enter text.

Any thoughts?

- Thanks.

Blockly question - ActivityBot CR servo controls?

$
0
0
I looked at all of the ActivityBot motor control blocks. If I am reading things correctly, it appears that it is not possible to use a variable for the motor speeds; there are either dropdowns for constant values in some blocks, or just places to enter constant values in the others, but no places to insert a variable.

The S3 motor control blocks do have places to connect variables.

My intent was to mirror in blocklyprop my C program that uses a Sony camera remote to control the ActivityBot.

I realize that the current major effort is to develop BlocklyProp for educational use with the S3, but I was wondering if there is the intent to further develop the C side. If so, I think the ability to use variables in the ABot motor controls would be useful.

Thanks
Tom

whiskers and piezospeaker

$
0
0
I assigned the following for homework:

Write a program that:
1. Makes a low tone if the left whisker is pressed
2. Makes a high lone if the right whisker is pressed
3. Makes a medium tone if both whiskers are pressed
4. Does nothing if neither whiskers are pressed.

The high and low tones work, but when both whiskers are pressed at the same time it reads it as either only the left or only the right. I tested it with TestWhiskers.bs2 and when I run that it displays 0's when both whiskers are pressed. RoamingWithWhiskers also runs correctly. So the circuit is correct, but I can't figure out why the code isn't working.

Please help! I'm attaching one of the kid's assignment.

BlocklyProp - How to post sample program?

$
0
0
What is best way to include in a message on this forum a BlocklyProp program? The problem is that the "code" is the image of the workspace.

You can do a snip or screen shot but that does not paste into the forum text. You can snip then save as file then attach file but that is time consuming.

You can switch to code view but then there is ambiguity about what blocks created the code.

Plus, if a response on this code wants to circle a problem or otherwise respond in a visual way it will be difficult.

To be honest, there probably is not a good way on this brand of forum. But I'm hoping someone more clever can figure it out. Maybe have another kind of doc to deposit a code image with a link here? In that case might as well just link to the project. But if it is private (which could be important) then won't work.

I'm sure the practice that is set will have some compromises, but we can at least make the practice consistent so we all use the same work-around

- John

BlocklyProp - referring to blocks by name. Establish a standard?

$
0
0
It is not easy to paste an image of a program into a forum post here. So I expect that in posts we will do a lot of referring in text to blocks by name. And at a greater scope, refer to a stack of blocks. It will be useful to standardize. This will also help me in educational materials. goals:
Keep short
It would be useful to include category and subcategories so the block can be found
It would be cool to have syntax to indicate the values for arguments

We could use the full text as written on the blocks but some blocks don't have text and for others it is cumbersome.

I saw somewhere that Parallax would establish standard names for blocks. I'm assuming those will be full names, not abbreviations.

To throw out an idea, what about some abbreviations that are a combo of what is written on the blocks, purpose, first few characters of category and maybe parentheses for arguments? I know is cumbersome, but seems better than alternates that I can think of.

Examples:

Comm/term/printT("hello",lineOn)
Var/new("myNumber")
Comm/term/printN(varMyNumber,dec,lineOff)
Pin/make(26,high)
Con/rep("countStudents",1,10,1){
Comm/prot/i2cSend(byte,1,12)
} //end rep
Comm/prot/i2cSend(byte,1,12)


BlocklyProp S3 - reset to demos

$
0
0
When a student is done the tutorials then the S3 is passed to the next student to begin. I want new student to start with factory-default program of the 8 demos. I assume the first student program that went into EEPROM over-wrote the factory program.

This link describes a future feature to do just that:
learn.parallax.com/support/reference/scribbler-3-robot-block-reference/actions/factory-reset
But I don't see that block implemented in my IDE.

Is there a link to the demo program so I can open and install on EEPROM manually?

Thanks.

Simple Project

$
0
0
Hi

I'm starting to plan one of my first project with you guys, and i'm wondering if anyone can give me some advice.

I would like to take the following components;

LM34 Temperature Sensor
http://www.parallax.com/product/604-00011

PING))) Ultrasonic Distance Sensor
http://www.parallax.com/product/28015

and output both the values they return to a small LCD screen

Is this quite an easy project? If so, can someone give me some pointers and advice to get started

Thanks all

BlocklyProp - Comment out blocks

$
0
0
Is there a way in BlocklyProp to comment out a block(s)?
This would not be to add a Cnt/Com block, but rather temporarily cause non-execution of a few existing blocks while troubleshooting.

My best ideas so far for hacks:
1-put them in a loop that runs 0 times. But adding that requires several mouse steps of dragging out the post-comment blocks, etc.
2-pull them over into a function "commentedOutBlocks" that is never called.

Creating new Blockly blocks?

$
0
0
Where can I find instructions on creating a new BlocklyProp block?

BlocklyProp S3 - Modify default program to reduce volume

$
0
0
I have three S3s running in a room while 15 other students are working on other projects. The combined volume of the S3s is high.
The factory default program is in SPIN which I haven't used in years. I would be grateful for help to change the parameters to reduce the volume of the tones.
I have attached a copy of the file as comes from factory but re-named it to avoid confusion.

Thanks, John

S3 Info Poster - reformatted to 8.5 x 11

$
0
0
My students start by going through the 8 demos that are factory-installed. This is before they do anything on the computer. They are wearing out the large color guide to demos that comes in the box. The PDF for the poster is available: https://parallax.com/downloads/scribbler-s3-robot-info-poster

I don't have a color printer that can print the PDF at its size of 40x50 cm. It would be great if someone could split the 16 panels of the doc into 16 pages that could be printed on letter-size paper. I don't have software or skills to use a PDF editor to dissect a file and flip some panels. Does anyone know how to do that right off the top of their head (and would be willing)?

Thanks


Should I2C Master ACK after last byte in read sequence?

$
0
0
I've never dived into the I2C protocol too much. However, I started doing a bit of a dive recently and noticed that I have some code in PropWare which is sending a NACK instead of an ACK after the last byte that a master reads. This seems crazy to me. Why would the master ever be coded to explicitly send a NACK? Here's an example:

i2c_no_ack.png

And this read sequence returns 0x01 to the calling function, so the master is indeed reading the value from the slave correctly.

serial terminal problems

$
0
0
When I run this listing, I get periodic errors where some of the data printed is bounced down as if it is a ghost. It happens usually when the clock rolls over to a new minute. Any ideas??
The extra lines are not updated.

BlocklyProp - Code Block?

$
0
0
Just wondering if there were any plans to add a code block so people could start to write code snippets in C or Spin. This would allow an orderly progression from using single purpose blocks to programming.

I'm attending the Electromechanical Engineering Technician program at Sheridan College in Brampton, Ontario and they use a product similar to BlocklyProp. The product they use, which shall remain nameless, doesn't seem as complete as BlocklyProp to my way of thinking.

Note that the editor I'm using to type this message keeps flagging BlocklyProp as a spelling error. You might want to fix that.

Sandy

Stall block usage in blockyprop program

$
0
0
Hi All, Anyone have a stall usage program, in Blockyprop, that they could post here,
Or could explain how to use the three items in the reference section. Thx, Bill

ActivityBot with SONY Remote

$
0
0
The Navigate With Infrared Flashlights tutorial for the ActivityBot was added to the rest of the ActivityBot tutorials on Friday:

http://learn.parallax.com/activitybot
http://learn.parallax.com/activitybot/navigate-infrared-flashlights

Here's a sneak peek at a related project that's coming soon to learn:

Circuit
http://learn.parallax.com/activitybot/build-ir-sensor-circuits
...although you can just use the IR receiver connected to P10.

Libraries
Copy the SONY Remote folder inside the attached zip to ...Documents/SimpleIDE/Learn/Simple Libraries/
Make sure you're running the latest version of SimpleIDE (0.9.43).
Restart SimpleIDE if it's running.

Test Code
Use the New Project button to create, name and save a new project.
Paste this code, then click Run with Terminal.
Point your remote at your ActivityBot and try pressing its various buttons. Verify that the digit keys match what's displayed as you press and hold them.
/*
  Test SONY Remote Keys.c
*/

#include "simpletools.h"                      // Library includes
#include "sonyremote.h"

int main()                                    // Main function
{
  ir_tLimit(1000);                            // -1 if no remote in 1 s

  while(1)                                    // Repeat indefinitely
  {
    print("%c ir key = %d%c",                 // Display key pressed
           HOME,       ir_key(10), CLREOL);
    pause(100);                               // 1/10 s before loop repeat
  }  
}


Navigation Code
Repeat the test code steps, but this time, use the Load EEPROM & Run button.
Unplug from the programming cable, and press and hold buttons to control. 2 or Channel up are forward, 8 or channel down are backward. 4 or volume down are turn left, 6 or volume up are turn right, and 1, 3, 7, and 9 are pivot keys.
/*
  ActivityBot SONY Remote Control.c
*/

#include "simpletools.h"                      // Library includes
#include "sonyremote.h"
#include "abdrive.h"

int key;                                      // Remote key variable

int main()                                    // Main funciton
{
  freqout(4, 2000, 3000);                     // Start beep
  drive_setRampStep(12);                      // 12 ticks/sec per 20 ms
  ir_tLimit(50);                              // Remote timeout = 50 ms

  while(1)                                    // Main loop
  {
    key = ir_key(12);                         // Get remote key code

    if(key == 2 || key == CH_UP)              // 2 or CH_UP -> Forward
      drive_rampStep(128, 128);
    if(key == 8 || key == CH_DN)              // 8 or CH_DN -> Backward
      drive_rampStep(-128, -128);
    if(key == 4 || key == VOL_DN)             // 4 or VOL_DN -> Left turn
      drive_rampStep(-128, 128);
    if(key == 6 || key == VOL_UP)             // 6 or VOL_UP -> Right turn 
      drive_rampStep(128, -128);
    if(key == 1)                              // 1 -> Left forward pivot
      drive_rampStep(128, 0);
    if(key == 7)                              // 7 -> Left backward pivot
      drive_rampStep(-128, 0);
    if(key == 3)                              // 3 -> Right forward pivot
      drive_rampStep(0, 128);
    if(key == 9)                              // 9 -> Right backward pivot
      drive_rampStep(0, -128);
    if(key == -1 || key == MUTE)              // no key or MUTE -> stay still
      drive_rampStep(0, 0);
  }  
}
Viewing all 293 articles
Browse latest View live