Show Posts
Pages: [1] 2 3 ... 176
1  Using Arduino / Programming Questions / Re: Libusb help on: July 22, 2014, 05:41:40 pm
You don't open a USB port to get a PC to talk to an Arduino.
If using libusb you do.
That is the entire point of libusb.
You open a connection to a device bulk end point and push data at it.
It is Host USB (PC) talking to Device USB (the leonardo) directly over USB.

To get a feel for libusb and the API functions, have a look at the documentation here:
Code:
http://libusb.sourceforge.net/doc/
If you google you can find lots of information out there on libusb

The challenge when using the Arduino environment is going to be that it has no debugging environment
The only way that is typically used is sending character data (printed messages)
from the Arduino board over a serial or virtual serial interface back to the host.
The default serial interface is named "Serial".
On Leonardo, that "serial" interface uses a virtual serial interface over USB.
But in this case, you can't use that because you will be using the USB for raw USB communication
with libusb.

If you had an AVR dragon, or a AVR ICE you could use Atmel Studio instead of the Arduino IDE
and have full source level debugging.
It can be done with the Arduino IDE (I've done it) but it is not easy to set up and I'm not sure
it could be done on Windows.

In the absence of source level debugging,
What you can do is use the USB for your libusb communication
and then use the real UART inside the 32u4 for your serial port.
It will be Serial1 instead of Serial.
See this:
http://arduino.cc/en/Guide/ArduinoLeonardoMicro?from=Guide.ArduinoLeonardo
RX will be pin 0 and TX will be pin 1.
You will need some sort of way to read the serial port data on the host.
Something like an FTDI cable or USB to TTL  module.

If you have to build the code on the PC vs the teacher giving you pre-compiled
executables, then you are going to need to set up a build environment.
You will need compilers, libraries, binutils, editor, make, shell,  revision control tools, etc...
Your teacher should be able to assist for that as I'm assuming the exercise is about
writing code to use USB communications using libusb vs how to locate and set up
all the needed tools to to create a build environment on Windows.
With linux, it is much simpler to do development since
all the tools are native and  pretty much built in,
since unix was designed by developers to do development.

Hope that helped.

--- bill




2  Using Arduino / Programming Questions / Re: Fast DigitalWrite, made from Wire lib source on: July 21, 2014, 07:27:47 pm
You removed the  set HIGH and LOW macros in fio_shiftOut() and then modified the code to
change the way the |= and &= operations were done and broke it.

This code is Oring in 1 bits to all the bits in the register but the correct one.
The AND is still stripping off the desired bit.

So the correct bit in the register is never getting set while corrupting
all the other bits in the register.
You can either fix the OR operation or go back to using the macros.

In terms of masking interrupts, the FIO code used the ATOMIC block macro
to ensure atomicity. It does mask interrupts but did it in a way that guaranteed
that the optimizer would never re-order the code - which is a risk depending
on how the code is written.
Worst case the re-ordering moves the interrupt mask and it no longer keeps
the operation atomic.

For portability to non AVR processors, you can re-define/create the ATOMIC macro when on other processors
just like the FIO code did.

In terms of what to make atomic, you will have decide whether to block
for the entire shift operation (slightly faster - but delays interrupts a bit longer),
or just during the bit twiddling of the register, which keeps interrupts masked
as short as possible.
The FIO code chose to minimize interrupt blocking.

--- bill


3  Using Arduino / Programming Questions / Re: #define, int or const int on: July 20, 2014, 11:06:39 pm
I guess nobody else uses enumerators? How odd. I just luvemup!

Whats more is they can have their size controlled, there is no behind the scenes conversions of integer literals. ( notice the : uint8_t )

now that is cool.
In the past enums were always ints, so on AVR you got worse code using enums
rather than const uint8_t
So while I'd prefer using enums in some situations, I often didn't use them on the AVR,
particularly when I was concerned about performance.

--- bill
4  Using Arduino / Displays / Re: LCD 122x32 with SED1520 on: July 20, 2014, 03:36:17 pm
This display is prepared for onboard negative power so I have soldered an ICL7660 on, and now I use a fixed resistor:
Very interesting.

Maybe there is some timing adjustment to do - there is no reset line and sometimes I have to power up a second time to get rid of some blur.

When it runs fine, it keeps running fine.

Can you further describe this "blur" misbehavior?
Or capture it in a video?
I'm not quite sure what is happening.
5  Using Arduino / Programming Questions / Re: #define, int or const int on: July 20, 2014, 12:30:55 pm

Not in the same sketch and the 2nd and 3rd lines need  ;  at the end.

Sorry, but this wasn't meant to be full code; I was only asking about the first part, as hinted in the post title.
Always keep in mind that coding isn't like horseshoes,
getting close often isn't good enough; the exact details tend to be really important.
So the three use cases you have seen are likely to be:
(no semi-colon on #define, and semi-colon on initializers.)
Code:
#define ledPin 13

Code:
int ledPin = 13;

Code:
const int ledPin = 13;

For something like a simple read only numeric constant, const is the usually the best choice
with todays compilers.
The worst choice is the middle one without the const declaration, since that one can not
be optimized as much and will often generate ram usage as well since without a static
declaration, the module has no way of knowing if another module will be altering the value
so it must reference the value from ram vs being able to assume that the value is a constant
or never touched by code external to this module.

I would recommend against declaring your data without the use of const
unless you need to be able to change it.

--- bill
6  Using Arduino / Displays / Re: LCD 122x32 with SED1520 on: July 20, 2014, 12:01:40 pm
Some of the sed1520 displays can work ok at room temperature
when the Vo signal is left unconnected or connected to ground.

How is your pot wired up?
It looks like it only has two wires going to it which won't allow any adjustment.
I also only see 1 voltage supply so no negative voltage which the link said was required
for the contrast circuit.

I bring all this up because the contrast circuit looks odd in the photo.
Do you get any contrast variation when you adjust the pot?
Am I missing something?


BTW, that demo is a GLCDv3 demo running openGLCD in GLCDv3 emulation mode.

--- bill
7  Using Arduino / Displays / Re: Newline char causes odd character on SainSmart 2004 20x4 I2C LCD on: July 20, 2014, 11:04:09 am
linefeed isn't the only character value that will cause issues.
Don't forget about carriage return.

--- bill
8  Using Arduino / Displays / Re: Can't figure out how to use special segments at bottom of LCD 8X1 display on: July 19, 2014, 10:39:20 pm
I will ask this question though: When you said:
Quote
To simplify the coding it only works on single LCD display and requires
that you name your lcd object "lcd".
 What is meant by naming the lcd object "lcd"?
That is just some fancy C++ words for the code expects a global variable named "lcd" to be used to control the lcd library.
The line at the top:
Code:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Is called a C++ constructor.
It is creating a global "object" from the LiquidCrystal class called lcd and the parameters
are being passed to the LiquidCrystal library and are used to fill in other data fields inside
that object.
The library allows controlling more than a single instance of the hardware. (multiple LCDs)
Each instance would get its own object.
The code I did makes an assumption that you have one of these LCD library objects and that it is
called lcd.
The code would need to be changed a bit if you wanted to be able to call it anything you wanted
or wanted to be able control more than one of them.

The LCDsetArrows() function creates a single custom character.
A custom character is 8 bytes. Each byte represents
a horizontal row of pixels starting at the top.
Only the lower 5 bits are used.
The code declares an 8 byte data array and asks it to be initalized to all zeros.
(In this case it really isn't necessary to zero out the memory)
The code only modifies the first byte since that is where bits
that control the arrows are.
It calls createChar() to send the custom character bytes to the LCD.
Then sets the address to 0x40, then writes the custom character.

The ternary in the function is a bit obtuse.
The line:
Code:
          (a0 ? 0b10000 : 0) | \

means
If a0 is nonzero use the value of 0b10000 else use a value of 0
All the values are ORd together then ORd into arrowData[0]

It probably would have been much simpler and clearer if this code:

Code:
       arrowData[0] = \
                (a0 ? 0b10000 : 0) | \
                (a1 ? 0b01000 : 0) | \
                (a2 ? 0b00100 : 0) | \
                (a3 ? 0b00010 : 0);

was replaced with this:
Code:
       if(a0) arrowData[0] |= 0b10000;
        if(a1) arrowData[0] |= 0b01000;
        if(a2) arrowData[0] |= 0b00100;
        if(a3) arrowData[0] |= 0b00010;

--- bill
9  Using Arduino / Programming Questions / Re: #define, int or const int on: July 19, 2014, 03:13:31 pm
But as you have so clearly pointed out, after 30+ years of programming! I clearly know nothing.
Maybe not nothing,  but my guess is that your 30+ years of programming  isn't 30+ years of C
programming and using macros because you seem to have a big misunderstanding of how cpp works.
How cpp does macro expansion and substitution hasn't really changed in 30+ years at least
not with respect to the simple substations in your examples.

In terms of why const may be better than defines
"it depends"
There are things that each can do that the other can't.

For simple uses of integer values that are constant,
 const is usually the better choice as it can offer type checking and is less likely to create odd errors
when there is a typo somewhere.

defines/macros can be used to do things that simple const variables can't
and in those cases, obviously macro defines must be used.

My assumption is that some of the  #define use in examples where a const probably
would have been more appropriate  is from the old guys
like me that have been doing C coding in embedded environments
for 30+ years and way back then there was no such thing as const, no function prototypes,
there was no C++,  optimizers were iffy at best,  so the best way to ensure you got compact
efficient code was often to use and push cpp to its limits.
Using a #define back then often generated better code than using a variable since
optimizers were not as good as they are today.
In the early days, everything was often essentially the same as todays "volatile"
so if you declared something as a variable vs a define, it used memory and hit memory
every single time you referenced it.
Back then the code generated was often about what you get with todays gcc with
optimization turned off.

You can still get  decent code without the optimizer turned off, but the
code you get will vary quite a bit depending on how you write it.

Essentially, since const didn't exist back then, , #define was what you used for constants.

And so for some of us that have been around for C for 30+ years,
those old habits and optimization techniques learned
over the decades are still being used even though many are no longer necessary.


--- bill
10  Using Arduino / Programming Questions / Re: How can I get assembly code out of a .ino file? on: July 19, 2014, 02:42:16 pm
Are you saying it ended in /tmp or some other directory down under /tmp?
It should be down in some directory under /tmp


The IDE creates a working directory down in /tmp and uses that area for all its immediate files
so that is where I placed the output files.
Since the directory used changes for each instance of the IDE, that is
 why I printed it from the script.



11  Using Arduino / Displays / Re: LCD 122x32 with SED1520 on: July 19, 2014, 12:47:38 pm
Depending on the modules you may need some of the openGLCD code updates that I just recently added
but are not in the latest published release.

Some 1520 based modules like the mtb368 use 2 chipselects and one enable vs 2 enables like the vk5121

If you have a module like this you will need the newer code.

The code works I just haven't released it yet as I'm not done with the documentation
updates I also want to include.


-- bill
12  Using Arduino / Programming Questions / Re: How can I get assembly code out of a .ino file? on: July 19, 2014, 12:39:43 pm
You can use this method but only on the 1.5x IDE and only if you are using linux.
Sorry, Windows is too wimpy and doesn't come with the tools that linux has.
Actually, it could be made to also work on Windows using a batch script wrapper
that sets up the PATH environment and then uses the sh/bash shell tool that
comes with the WINAVR tools that the Windows IDE comes with to call the same
shell script, but it wasn't  a priority for me since I don't use Windows.

It will create a listing file and a symbol table file every time you do a build
from the IDE.
Once you set it up, it "just happens".
It will echo out to the console window where the files are and you can go look at them.

The listing file will be not just your sketch but everything that was linked into the image
and it will have intermixed C code to make it easier to find and examine the assembler.

Instructions are in the attached script but here is a summary:

Here is what you need to do.
In your 1.5x install tree edit the platform.txt file for the AVR processor.
It will be
{installdir}/hardware/avr/platform.txt

Change this:
Code:
## Create hex
recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"

to this:
Code:
## Create hex
#recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"

## Bills objcopy wrapper
recipe.objcopy.hex.pattern="{compiler.path}../../avr-objcopy-wrapper.sh" "{compiler.path}{compiler.elf2hex.cmd}" "{compiler.elf2hex.flags}" "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"

Then install the shell script attached in:

{installdir}/hardware/tools

--- bill


13  Using Arduino / Displays / Re: LCD 122x32 with SED1520 on: July 19, 2014, 11:42:31 am
In terms of that referenced library mentioning  "write only".
A library can choose to use a frame buffer and never read data from the display.
That doesn't necessarily mean that the module is write only.
For example, the u8glib library operates in "write only" mode
but it still does reads when interfacing to displays like ks0108 and sed1520 to check for ready status.

openGLCD has a read cache mode where it will never read data from the display,
however, it will still read the status from the display to be able to tell when
it can send data & commands to the display.

Are you saying that traces just to the left of each of the labeled fat
ground pin 78 traces are the E signals and  go to  glcd module pins 6 an 7?

Can you show a photo of the other side of the board?

On the other side  are there no traces running to glcd module pins 11 and 18?

If so, there doesn't seem to be enough pins.
With motorola mode (68 series) you need a r/w pin and a strobe.
With intel mode (80 series) you need a read strobe and a write strobe.

Motorola mode could work if the r/w pin was grounded but then
you could never read the status register to know when commands
have completed.

There would be no way to run Intel mode since the write stobe pin
is stuck grounded.

It seems very odd that the module would leave two pins (11 & 18) not connected
to anything  and hard wire the r/w(WR) pin to ground.

If the module has the r/w(WR) pin hardwired to ground,
openGLCD will not work with the module "as is" since the library
wants to read the status register to know when the module is ready
to receive data/commands.
Without this, the code would have to be changed to use blind delays instead
which requires code changes.
Also, I have no idea how long those delays need to be.



14  Using Arduino / Displays / Re: LCD 122x32 with SED1520 on: July 19, 2014, 01:09:41 am
I no longer maintain the glcd library but have created a newer library openGLCD.
It can be found here: https://bitbucket.org/bperrybap/openglcd/wiki/Home
It is licensed GPLv3.
It is a superset of the glcd library with bug fixes, and many new features.
If interested, read the wiki and then the html documentation.

You need to see if you can find a better data sheet to help clarify the
pins. As is common in these datasheets, this data sheet has errors in it.
The pinout on pages 4 and 8 don't agree, and both are wrong.
There must be at least a r/w pin for 68 series mode and both read and write
pins for 80 series mode.

Did the vendor give you this datasheet?
You might try googling for the part number on the back of the board.

Getting the correct pinout information is critical as hooking up wires
incorrectly can potentially damage the glcd or the Arduino.

If you can find a better datasheet I can help you get it up and running on openGLCD.

--- bill
15  Using Arduino / Displays / Re: Can't figure out how to use special segments at bottom of LCD 8X1 display on: July 18, 2014, 09:27:29 pm
I tracked down why you have to tell the LCD library it has two lines.
The issue is that if you initialize the library with only 1 line it sends
a command to the LCD chip indicating that it is a single line LCD and
that disables the pixel signals for the second line where the arrow icons are.
The arrow icons are essentially 4 GIANT pixels on the top row of pixels starting
on the left of the second line
Therefore, to use the arrow icons you have tell the chip it has more than 1 line.

I took a stab at creating some sample code.
I attached it.
You can ignore/remove my commented out  hd44780 lcd headers  and lcd constructor
that is used for testing.

I numbered the arrows starting at 0 vs 1 but if that bothers you, you can change the code.
Not sure about your C experience but it if you are new to C
it may use a few things that may be a bit more advanced than you have seen like
a ternary operator (the ? mark) which works like an if statement.

There are two functions, one to set individual arrows, and the other sets
all the arrows at once.

To simplify the coding it only works on single LCD display and requires
that you name your lcd object "lcd".


if it doesn't work or you have questions about the code, just ask.


--- bill
Pages: [1] 2 3 ... 176